![](/img/trans.png)
[英]Updating a record by query in ElasticSearch using olivere/elastic in google go
[英]Elasticsearch query to filter documents where value1 == value2 with Go olivere/elastic
我需要建立查詢來獲取文檔,其中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
}
query = query.Filter(elastic.NewScriptQuery(elastic.NewScript("doc['val1'].value == doc['val2'].value")))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.