按数组项或空数组过滤

我正在尝试按必须为空或包含项1的数组进行过滤。

{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [
            {
              "terms": {
                "memberOrganizationFamilyIds": [
                  1
                ]
              }
            }
          ],"must_not": [
            {
              "exists": {
                "field": "memberOrganizationFamilyIds"
              }
            }
          ]
        }
      }
    }
  }
}

根据文档,这应该是应该的,但它不起作用。

如果我们应用第一个过滤器,它将起作用。

{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must": [
            {
              "terms": {
                "memberOrganizationFamilyIds": [
                  1
                ]
              }
            }
          ]
        }
      }
    }
  }
}

如果我们应用第二个过滤器,它也将起作用。

{
  "query": {
    "bool": {
      "filter": {
        "bool": {
          "must_not": [
            {
              "exists": {
                "field": "memberOrganizationFamilyIds"
              }
            }
          ]
        }
      }
    }
  }
}

但不能在一起。

wr5279 回答:按数组项或空数组过滤

  

我正在尝试按必须为空包含项目1的数组进行过滤

尝试此操作,您应该添加should(意思是or

{
"query": {
    "bool": {
      "filter": {
        "bool": {
          "should": [
            {
              "terms": {
                "memberOrganizationFamilyIds": [
                  1
                ]
              }
            },{
              "bool": {
                "must_not": [
                  {
                    "exists": {
                      "field": "memberOrganizationFamilyIds"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }
  }
}
本文链接:https://www.f2er.com/3117666.html

大家都在问