mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-29 08:12:21 +00:00
fix dse
This commit is contained in:
parent
25ffbb0f29
commit
9bb2504f9b
@ -243,7 +243,11 @@ func insertDocument(db string, table string, obj map[string]interface{}) {
|
|||||||
```go
|
```go
|
||||||
func query(indexName string, typeName string) (*elastic.SearchResult, error) {
|
func query(indexName string, typeName string) (*elastic.SearchResult, error) {
|
||||||
// 通过 bool must 和 bool shoud 添加 bool 查询条件
|
// 通过 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)
|
searchService := esClient.Search(indexName).Type(typeName)
|
||||||
res, err := searchService.Query(q).Do()
|
res, err := searchService.Query(q).Do()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user