ElasticSearch中的空桶

时间:2018-09-21 21:18:02

标签: elasticsearch

我正在从嵌套聚合中获取空存储桶。我希望得到所有键和嵌套存储桶及其值的结果,但是无论我如何对其进行切片,我总是最终得到一个空存储桶结果集。 使用弹性v6.2.4 她是复制的步骤:

PUT aggregation_test
{"settings": {"number_of_shards": 1}}

PUT aggregation_test/_mapping/doc
{
  "properties": {
    "Description": {
      "type": "text"
    },
    "string_attributes": {
      "type": "nested",
      "properties": {
        "key": {"type": "text"},
        "value": {"type": "text"}
      }
    }
  }
}

然后填充数据

POST aggregation_test/doc/1
{
  "Description": "one",
  "string_attributes": [
    { "key": "Variant", "value": "Red"},
    { "key": "Variant", "value": "Yellow"},
    { "key": "Variant", "value": "Blue"},
    { "key": "EcoFriendly", "value": "Yes"}
  ]
}

POST aggregation_test/doc/2
{
  "Description": "two",
  "string_attributes": [
    { "key": "Variant", "value": "Red"},
    { "key": "Variant", "value": "Green"},
    { "key": "Variant", "value": "Blue"},
    { "key": "EcoFriendly", "value": "No"}
  ]
}

POST aggregation_test/doc/3
{
  "Description": "three",
  "string_attributes": [
    {"key": "Variant", "value": "Red"},
    {"key": "Variant", "value": "Green"},
    {"key": "Variant", "value": "Blue"}
  ]
}

这是我的汇总

GET aggregation_test/_search
{
  "size": 0,
  "aggs": {
    "nested_level": {
      "nested": {
        "path": "string_attributes"
      },
      "aggs": {
        "keyword_field": {
          "terms": {
            "field": "string_attributes.key.keyword"
          }, "aggs": {
            "value_field": {
              "terms": {"field": "string_attributes.value.keyword"}
            }
          }
        }
      }
    }
  }
}

和结果

{
  "hits": {
    "total": 3,
    "max_score": 0,
    "hits": []
  },
  "aggregations": {
    "nested_level": {
      "doc_count": 11,
      "keyword_field": {
        "doc_count_error_upper_bound": 0,
        "sum_other_doc_count": 0,
        "buckets": []
      }
    }
  }
}

知道我为什么看不到任何存储桶信息吗?

1 个答案:

答案 0 :(得分:1)

在查询中,它以字段string_attributes.key.keywordstring_attributes.value.keyword为目标,但是根据您的架构,它没有keyword和{{1}的key字段}。

您必须更改架构以在其中添加value字段

keyword

希望它能起作用