我需要构建查询来获取 doc.value1 == doc.value2 的文档{ "query": { "bool" : { "filter" : [{ "script" : { "script" : { "source": "doc['val1'].value == doc['val2'].value", "lang": "painless" } } }] } }}这是我需要用 olivere/elastic 构建的,如果我将其作为 POST 请求发送,它就可以工作。在 golang 我有类似的东西"github.com/olivere/elastic"...query := elastic.NewBoolQuery()// then add something to this query or leave it empty it works fine// but if I add query = query.Filter(elastic.NewBoolQuery().Must(elastic.NewScript("doc.['val1'].value == doc.['val2'].value")))// I'm getting: Error 400 (Bad Request): [source] query malformed,// no start_object after query name [type=parsing_exception]// Then i run it like:client, err := elastic.NewClient()if err != nil { fmt.Println(err) return}resp, err := client.Search("myIndex").Type("myDoc").Query(query).TrackTotalHits(true).Size(limit).Do(context.Background()) if err != nil { fmt.Println(err) return }
1 回答
饮歌长啸
TA贡献1951条经验 获得超3个赞
query = query.Filter(elastic.NewScriptQuery(elastic.NewScript("doc['val1'].value == doc['val2'].value")))
- 1 回答
- 0 关注
- 137 浏览
添加回答
举报
0/150
提交
取消