feat:优化es查询规则

This commit is contained in:
henry
2021-12-24 09:13:16 +08:00
parent b62ee9c3d9
commit ebf74435ef
5 changed files with 39 additions and 55 deletions

View File

@ -10,6 +10,7 @@ import (
type (
// SearchParams 搜索参数
SearchParams struct {
TermParams map[string]interface{}
MustParams map[string]interface{}
ShouldParams map[string]interface{}
}
@ -30,13 +31,21 @@ func Search(src interface{}, index string, params *SearchParams, page, pageSize
query := elastic.NewBoolQuery()
if params != nil {
if params.TermParams != nil && len(params.TermParams) > 0 {
for k, v := range params.TermParams {
// 精确查找
query.Must(elastic.NewMatchPhraseQuery(k, v))
}
}
if params.MustParams != nil && len(params.MustParams) > 0 {
for k, v := range params.MustParams {
// 分词匹配
query.Must(elastic.NewMatchQuery(k, v))
}
}
if params.ShouldParams != nil && len(params.ShouldParams) > 0 {
for k, v := range params.ShouldParams {
// 分词匹配,查询到一个即可
query.Should(elastic.NewMatchQuery(k, v))
}
}