弹性搜索-空数组?

时间:2019-02-25 01:52:59

标签: elasticsearch

我试图返回“ hit”以查找空数组,我有以下查询:

GET /universally_searchable/_search
{
  "query": {
  "bool": {
    "must": [
      {
        "query_string": {
          "query": "*",
          "fields": [
            "name^
          ]
        }
      }
    ],
    "should": [],
    "must_not": [
      {
        "exists": {
          "field": "extensions.organization.markets"
        }
      }
    ]
  }
}
}

extensions.organization.markets需要为空数组,但是所有结果上都存在该数组,因此我得到了所有我只希望拥有空市场数组的组织。

1 个答案:

答案 0 :(得分:1)

您需要使用nested objects,并且我认为您需要添加适当的映射

{
  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "*",
            "fields": [
              "name^"
            ]
          }
        }
      ],
      "should": [],
      "must_not": [
        {
          "nested": {
            "path": "extensions.organization",
            "query": {
              "exists": {
                "field": "markets"
              }
            }
          }
        }
      ]
    }
  }
}