嵌套字段空值聚合在elasticsearch查询中返回错误的值

时间:2017-06-28 07:51:17

标签: arrays json elasticsearch

我有以下数据嵌套映射。

{
   "index": {
      "mappings": {
         "type": {
            "_all": {
               "enabled": false
            },
            "properties": {
               "A": {
                  "type": "nested",
                  "properties": {
                     "productmaster_FABRIC": {
                        "type": "string",
                        "index": "not_analyzed",
                        "fielddata": {
                           "format": "doc_values",
                           "loading": "eager_global_ordinals"
                        },
                        "fields": {
                           "hash": {
                              "type": "murmur3",
                              "precision_step": 2147483647
                           }
                        },
                        "null_value": "null",
                        "ignore_above": 10922
                     }
                  }
               },
               "purchaseli_QTY": {
                  "type": "integer"
               }
            }
         }
      }
   }
}

对象的样本数据是

[{purchaseli_QTY : 1, productmaster_FABRIC:"cotton"},{purchaseli_QTY : 2, productmaster_FABRIC:"polyster"}, {purchaseli_QTY : 1, productmaster_FABRIC:"rymonds"},
{purchaseli_QTY : 8, productmaster_FABRIC:""},{purchaseli_QTY : 5, productmaster_FABRIC:"cotton"},{purchaseli_QTY : 2, productmaster_FABRIC:"polyster"}, {purchaseli_QTY : 5, productmaster_FABRIC:"rymonds"},
{purchaseli_QTY : 9, productmaster_FABRIC:""},{purchaseli_QTY : 1, productmaster_FABRIC:"cotton"},{purchaseli_QTY : 2, productmaster_FABRIC:"polyster"}, {purchaseli_QTY : 1, productmaster_FABRIC:"rymonds"},
{purchaseli_QTY : 8, productmaster_FABRIC:""},{purchaseli_QTY : 1, productmaster_FABRIC:"cotton"},{purchaseli_QTY : 2, productmaster_FABRIC:"polyster"}, {purchaseli_QTY : 1, productmaster_FABRIC:"rymonds"},
{purchaseli_QTY : 8, productmaster_FABRIC:""}]

这是我的查询,总和,avg或任何其他聚合将返回空字段的错误结果,而不是计数聚合。

{
    "size": 0,
    "_source": false,
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": [{
                        "query": {
                            "nested": {
                                "path": "A",
                                "query": {
                                    "term": {
                                        "A.productmaster_FABRIC": ""
                                    }
                                }
                            }
                        }
                    }]
                }
            }
        }
    },
    "aggs": {
        "sumpurchase": {
            "sum": {
                "field": "purchaseli_QTY"
            }
        }
    }
}

我正在使用elasticsearch 2.2.0版本。有人可以帮我解决这个问题吗?

0 个答案:

没有答案