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

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

golang 中的 Elasticsearch 使用 olivere/elastic

golang 中的 Elasticsearch 使用 olivere/elastic

Go
千巷貓影 2023-07-31 15:35:49
我正在嘗試在我的 go 應用程序中實現 elasticsearch。我正在使用https://github.com/olivere/elastic庫進行 go,elasticsearch 在 docker 容器中運行。我成功連接到elasticsearch并創建索引,之后我嘗試將數據保存到elasticsearch,也成功了。當我運行查詢時我開始遇到問題我的映射看起來像這樣   "mappings":{        "item":{            "properties":{                "id":{                    "type":"integer"                },                "title":{                    "type":"text"                },                "description":{                    "type":"text"                },                "userid":{                    "type":"integer"                }            }        }    }我試圖按這樣的標題查詢 es ,但得到空響應。如果我從 Search() 中刪除查詢,則會列出所有已保存的項目。我還嘗試與 newBoolQuery 和 newMatchPhrase 結合使用,它也返回空響應。query := elastic.NewTermQuery("title", "Hello there")searchResult, err := elasticClient.Search().    Index("items").    Query(query).    Pretty(true).    Do(ctx)if err != nil {    return nil, err}return searchResult, nil回復 : {    "id": 81,    "message": "Search successfull",    "data": {        "took": 1,        "_scroll_id": "",        "hits": {            "total": 0,            "max_score": null,            "hits": []        },        "suggest": null,        "aggregations": null,        "timed_out": false,        "_shards": {            "total": 1,            "successful": 1,            "failed": 0        }    }}
查看完整描述

1 回答

?
交互式愛情

TA貢獻1712條經驗 獲得超3個贊

我認為你應該根據你的情況進行選擇,如術語查詢NewMatchQuery文檔中所述

避免對文本字段使用術語“查詢”。

默認情況下,Elasticsearch 會更改文本字段的值作為分析的一部分。這可能會使查找文本字段值的精確匹配變得困難。

要搜索文本字段值,請改用匹配查詢。

您沒有分享您索引的示例文檔以及您想要查找的內容,但類似下面的內容應該對您的情況有所幫助

query?:=?NewMatchQuery("title",?"Hello?there")

希望有幫助。


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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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