Elastic的should + bool 多字段完全匹配或查找

 1 {
 2   "aggs": {},
 3   "from": 0,
 4   "query": {
 5     "bool": {
 6       "must": [],
 7       "must_not": [],
 8       "should": [
 9         {
10           "bool": {
11             "must": [
12               {
13                 "term": {
14                   "name": "ming"
15                 }
16               },
17               {
18                 "term": {
19                   "age": "30"
20                 }
21               }
22             ]
23           }
24         },
25         {
26           "bool": {
27             "must": [
28               {
29                 "term": {
30                   "name": "qiang"
31                 }
32               },
33               {
34                 "term": {
35                   "age": "18"
36                 }
37               }
38             ]
39           }
40         }
41       ]
42     }
43   },
44   "size": 10000,
45   "sort": [],
46   "track_total_hits": true
47 }

就是 (qiang + 18) or (ming + 30)

 为什么有时候需要显示声明

minimum_should_match:1
query[bool][minimum_should_match]:1
 
posted @ 2021-06-28 12:01  许伟强  阅读(501)  评论(0编辑  收藏  举报