亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Go olivere/elastic 進行 Elasticsearch 查詢以過濾

使用 Go olivere/elastic 進行 Elasticsearch 查詢以過濾

Go
慕蓋茨4494581 2023-07-17 17:16:57
我需要構建查詢來獲取 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")))



查看完整回答
反對 回復 2023-07-17
  • 1 回答
  • 0 關注
  • 191 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號