跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • es 查询条件不生效
未分類
8 5 月 2020

es 查询条件不生效

es 查询条件不生效

資深大佬 : chenguoyu 26

{     "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)

  • 資深大佬 : aureole999

    should 和 must 并列的话 should 就可以不匹配了。must 那边 rule_level 已经必须是 4 了,should 那边就没有了。
    除非你的 rule_level 是个列表,那 rule_level 同时包含 4,5 的会在最前面。

  • 資深大佬 : misaka19000

    should 我记得有个 minimum_match 属性

  • 資深大佬 : misaka19000

    https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html

    如果没有 must,默认值为 1 ;如果有 must,默认值为 0

    如果我没记错的话 : )

  • 資深大佬 : woniu127

    https://www.cnblogs.com/chenmz1995/p/11446422.html

  • 資深大佬 : rqrq

    这个就等同于 sql 的 or 条件,不确定就写成 sql 语句然后用 /_sql/translate 接口转 dsl

  • 資深大佬 : j747677392

    should 相当于 or,must 相当于 and 两个同级 should 就没效果了。不知道你要实现什么,一般最外层只用 should 或 must 或 mustnot 其中一个

  • 資深大佬 : enrio

    你知道自己想查什么吗?

  • 主 資深大佬 : chenguoyu

    @enrio #7 我想要的效果是类似于 sql 中
    where
    (条件 1 and 条件 2)
    or
    (条件 3 and 条件 4)
    and
    (条件 5 or 条件 6)
    这样的

  • 資深大佬 : enrio

    @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

    @chenguoyu 这排版有够恶心
    看这个图片,https://pic.downk.cc/item/5e9d03c1c2a9a83be50e60b8.png 。

  • 資深大佬 : Flourite

    用 terms

  • 資深大佬 : yang2yang

    9 说的对

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具