es filter中使用should

搜索 state = 0 或者 state不存在的记录

 {
        "query": {
          "bool": {
            "filter": {
              "bool": {
                "should": [
                  { "term": { "state": 0 } },
                  { "bool": { "must_not": { "exists": { "field": "state" } } } }
                ]
              }
            }
          }
        }
},
搜索 (state = 0 或者 state不存在的记录) and payState = 1  :这句有待验证
{
        query: {
          bool: {
            filter: [{
                "bool": {
                  "should": [
                    { "term": { "state": 0 } },
                    { "bool": { "must_not": { "exists": { "field": "state" } } } }
                  ]
                }
              },
              { term: { payState: 1 } }
            ]

          }
        }
      }

猜你喜欢

转载自blog.csdn.net/QQ2856639881/article/details/88087340