1
0
mirror of https://github.com/chai2010/advanced-go-programming-book.git synced 2025-05-29 08:12:21 +00:00
This commit is contained in:
Xargin 2018-07-21 20:34:03 +08:00
parent 25ffbb0f29
commit 9bb2504f9b

View File

@ -243,7 +243,11 @@ func insertDocument(db string, table string, obj map[string]interface{}) {
```go
func query(indexName string, typeName string) (*elastic.SearchResult, error) {
// 通过 bool must 和 bool shoud 添加 bool 查询条件
query := elastic.NewBoolQuery().Must(elastic.NewMatchPhraseQuery("id", 1))
q := elastic.NewBoolQuery().Must(elastic.NewMatchPhraseQuery("id", 1),
elastic.NewBoolQuery().Must(elastic.NewMatchPhraseQuery("male", "m")))
q = q.Should(elastic.NewMatchPhraseQuery("name", "alex"),
elastic.NewMatchPhraseQuery("name", "xargin"))
searchService := esClient.Search(indexName).Type(typeName)
res, err := searchService.Query(q).Do()