从ElasticSearch过滤空对象

时间:2018-01-22 22:58:23

标签: elasticsearch

我必须在ElasticSearch查询中过滤这样的有效负载:

{
  "bestPrices": {
    "cia1": {},
    "cia2": {}
  }
}

我必须得到的结果如下:

{
  "bestPrices": {
    "cia1": {
      "gol": {
        "price1": 799,
        "price2": null,
        "miles": 25000
      }
    },
    "cia2": {
      "gol": {
        "price1": null,
        "price2": null,
        "miles": null
      }
    }
  }
}

我正在尝试exists查询,但似乎不适用于这种特殊情况:

{
  "exists": {
    "field": "searchIntention.bestSalePrices.cia1"
  }
}

我使用的是ElasticSearch 6.1

1 个答案:

答案 0 :(得分:0)

Exists Query的Elasticsearch文档指定null[][null]符合不存在的值。因此,我相信所有其他值,包括空对象({})都将被视为非空。如果始终填充go1对象的cia成员,则可以尝试在该字段上使用exists

{
  "exists": {
   "field": "searchIntention.bestSalePrices.cia1.go1"
  }
}