我从嵌套聚合中获取空存储桶。我期望得到所有键和嵌套存储桶及其值的结果,但是无论我如何对其进行 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.keyword
和string_attributes.value.keyword
字段为目标,但是根据您的模式,它没有keyword
和key
的value
字段。
您必须更改架构以在其中添加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/