elasticsearch - ElasticSearch中的空桶

标签 elasticsearch

我从嵌套聚合中获取空存储桶。我期望得到所有键和嵌套存储桶及其值的结果,但是无论我如何对其进行 slice ,我总是最终得到一个空存储桶结果集。
使用 flex 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": []
      }
    }
  }
}

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

最佳答案

查看查询时,它以string_attributes.key.keywordstring_attributes.value.keyword字段为目标,但是根据您的模式,它没有keywordkeyvalue字段。

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

PUT aggregation_test 
{
  "mappings": {
    "doc": {
      "properties": {
        "Description": {
          "type": "text"
        },
        "string_attributes": {
          "type": "nested",
          "properties": {
            "key": {
              "type": "text",
              "fields": {
                "keyword": { // add this
                  "type": "keyword" // type should be keyword for proper aggregation
                }
              }
            },
            "value": {
              "type": "text",
              "fields": {
                "keyword": { // add this
                  "type": "keyword" 
                }
              }
            }
          }
        }
      }
    }
  }
}

希望能奏效

关于elasticsearch - ElasticSearch中的空桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52451175/

相关文章:

elasticsearch - Elasticsearch 地理空间搜索实现

elasticsearch - 删除快照存储库超时

ssl - DBeaver SSL 已禁用

python - Elasticsearch查询不会带来任何成功

elasticsearch - 获取所有不包含 key 的文档?

elasticsearch - 计算 Elasticsearch 聚合中的非唯一项?

grails - 字符串json到elasticSearch SearchResponse对象?

node.js - Elasticsearch 在 Node js 中使用滚动显示所有结果

elasticsearch - 嵌套查询在 bool 中写入必须和应该

logging - ELK - Logstash + Redis - 数据复制