{ "from": 3890, "size": 10, "query": { "bool": { "must": [ { "range": { "receive_log_time": { "from": 1587225600000, "to": 1587288897000, "include_lower": true, "include_upper": true } } }, { "bool": { "must": { "term": { "rule_level": "4" } } } } ], "should": { "bool": { "must": { "term": { "rule_level": "5" } } } } } } }
其中 should 下面的条件没有生效,请问有人知道原因吗?
1 aureole999 2020-04-19 18:09:09 +08:00 ![]() should 和 must 并列的话 should 就可以不匹配了。must 那边 rule_level 已经必须是 4 了,should 那边就没有了。 除非你的 rule_level 是个列表,那 rule_level 同时包含 4,5 的会在最前面。 |
![]() | 2 misaka19000 2020-04-19 18:17:10 +08:00 should 我记得有个 minimum_match 属性 |
![]() | 3 misaka19000 2020-04-19 18:19:44 +08:00 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html 如果没有 must,默认值为 1 ;如果有 must,默认值为 0 如果我没记错的话 : ) |
![]() | 4 woniu127 2020-04-19 20:42:08 +08:00 |
5 rqrq 2020-04-19 23:25:52 +08:00 这个就等同于 sql 的 or 条件,不确定就写成 sql 语句然后用 /_sql/translate 接口转 dsl |
![]() | 6 j747677392 2020-04-19 23:36:29 +08:00 should 相当于 or,must 相当于 and 两个同级 should 就没效果了。不知道你要实现什么,一般最外层只用 should 或 must 或 mustnot 其中一个 |
![]() | 7 enrio 2020-04-20 00:21:58 +08:00 你知道自己想查什么吗? |
![]() | 8 chenguoyu OP |
![]() | 9 enrio 2020-04-20 10:03:43 +08:00 ![]() @chenguoyu bool:{ should:[ { bool:{ must:[条件 1,条件 2] } }, { bool:{ must:[ { bool:{ must:[条件 3,条件 4] } }, { bool:{ should:[条件 5,条件 6], mininum_should_match:1 } } ] } } ], mininum_should_match:1 } |
![]() | 10 enrio 2020-04-20 10:08:15 +08:00 ![]() |
![]() | 11 dV9zZM1wROuBT16X 2020-04-20 10:41:55 +08:00 用 terms |
![]() | 12 yang2yang 2020-04-20 11:03:01 +08:00 9 楼说的对 |