我正在用 golang 編寫一個函數來搜索已編入索引的 elasticsearch 文檔中的字符串。我正在使用 elasticsearch golang 客戶端elastic。例如考慮對象是推文,type Tweet struct { User string Message string Retweets int}搜索功能是func SearchProject() error{ // Search with a term query termQuery := elastic.NewTermQuery("user", "olivere") searchResult, err := client.Search(). Index("twitter"). // search in index "twitter" Query(&termQuery). // specify the query Sort("user", true). // sort by "user" field, ascending From(0).Size(10). // take documents 0-9 Pretty(true). // pretty print request and response JSON Do() // execute if err != nil { // Handle error panic(err) return err } // searchResult is of type SearchResult and returns hits, suggestions, // and all kinds of other information from Elasticsearch. fmt.Printf("Query took %d milliseconds\n", searchResult.TookInMillis) // Each is a convenience function that iterates over hits in a search result. // It makes sure you don't need to check for nil values in the response. // However, it ignores errors in serialization. If you want full control // over iterating the hits, see below. var ttyp Tweet for _, item := range searchResult.Each(reflect.TypeOf(ttyp)) { t := item.(Tweet) fmt.Printf("Tweet by %s: %s\n", t.User, t.Message) }此搜索正在打印用戶“olivere”的推文。但是如果我給出“橄欖”,那么搜索就不起作用了。如何搜索屬于用戶/消息/轉推的字符串?有人可以幫我解決這個問題嗎?謝謝
2 回答

一只萌萌小番薯
TA貢獻1795條經驗 獲得超7個贊
multiQuery := elastic.NewMultiMatchQuery(
term,
"name", "address", "location", "email", "phone_number", "place", "postcode",
).Type("phrase_prefix")
- 2 回答
- 0 關注
- 253 瀏覽
添加回答
舉報
0/150
提交
取消