es 查询条件不生效 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
chenguoyu
V2EX    Java

es 查询条件不生效

  •  
  •   chenguoyu 2020-04-19 17:40:34 +08:00 3614 次点击
    这是一个创建于 2010 天前的主题,其中的信息可能已经有所发展或是发生改变。
    { "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 下面的条件没有生效,请问有人知道原因吗?

    12 条回复    2020-04-20 11:03:01 +08:00
    aureole999
        1
    aureole999  
       2020-04-19 18:09:09 +08:00   1
    should 和 must 并列的话 should 就可以不匹配了。must 那边 rule_level 已经必须是 4 了,should 那边就没有了。
    除非你的 rule_level 是个列表,那 rule_level 同时包含 4,5 的会在最前面。
    misaka19000
        2
    misaka19000  
       2020-04-19 18:17:10 +08:00
    should 我记得有个 minimum_match 属性
    misaka19000
        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

    如果我没记错的话 : )
    woniu127
        4
    woniu127  
       2020-04-19 20:42:08 +08:00
    rqrq
        5
    rqrq  
       2020-04-19 23:25:52 +08:00
    这个就等同于 sql 的 or 条件,不确定就写成 sql 语句然后用 /_sql/translate 接口转 dsl
    j747677392
        6
    j747677392  
       2020-04-19 23:36:29 +08:00
    should 相当于 or,must 相当于 and 两个同级 should 就没效果了。不知道你要实现什么,一般最外层只用 should 或 must 或 mustnot 其中一个
    enrio
        7
    enrio  
       2020-04-20 00:21:58 +08:00
    你知道自己想查什么吗?
    chenguoyu
        8
    chenguoyu  
    OP
       2020-04-20 09:36:33 +08:00
    @enrio #7 我想要的效果是类似于 sql 中
    where
    (条件 1 and 条件 2)
    or
    (条件 3 and 条件 4)
    and
    (条件 5 or 条件 6)
    这样的
    enrio
        9
    enrio  
       2020-04-20 10:03:43 +08:00   1
    @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
    }
    enrio
        10
    enrio  
       2020-04-20 10:08:15 +08:00   1
    @chenguoyu 这排版有够恶心
    看这个图片,https://pic.downk.cc/item/5e9d03c1c2a9a83be50e60b8.png
    dV9zZM1wROuBT16X
        11
    dV9zZM1wROuBT16X  
       2020-04-20 10:41:55 +08:00
    用 terms
    yang2yang
        12
    yang2yang  
       2020-04-20 11:03:01 +08:00
    9 楼说的对
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1656 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 33ms UTC 16:23 PVG 00:23 LAX 09:23 JFK 12:23
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86