我在嵌套聚合后创建存储桶有问题
"events.name12": {
"filter": {},
"aggs": {
"events": {
"nested": {
"path": "events"
},
"aggs": {
"filtered.events": {
"filter": {
"terms": {
"events.id": [
448,
435,
338,
364
]
}
},
"aggs": {
"filtered.roles": {
"nested": {
"path": "events.role"
},
"aggs": {
"filtered": {
"filter": {},
"aggs": {
"events.name": {
"terms": {
"field": "events.name",
"size": 5
}
},
"events.name_count": {
"cardinality": {
"field": "events.name"
}
}
}
}
}
}
}
}
}
}
}
}
我想通过id过滤事件,然后是特定的role.name,最后我需要来自event.name的桶
结果:
"events.name12": {
"doc_count": 617,
"events": {
"doc_count": 1278,
"filtered.events": {
"doc_count": 625,
"filtered.roles": {
"doc_count": 625,
"filtered": {
"doc_count": 625,
"events.name": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": []
},
"events.name_count": {
"value": 0
}
}
}
}
}
}
我认为它们是空的,因为上下文已更改为events.role。 但是我如何通过不同级别的嵌套字段实现这种过滤?
映射:
{
"dev.directory.11" : {
"mappings" : {
"profile" : {
"properties" : {
"company_name" : {
"type" : "string",
"fields" : {
"raw" : {
"type" : "string",
"index" : "not_analyzed"
}
}
},
"email" : {
"type" : "string",
"index" : "not_analyzed"
},
"events" : {
"type" : "nested",
"properties" : {
"categories" : {
"type" : "nested",
"properties" : {
"ancestors" : {
"type" : "string",
"index" : "not_analyzed"
},
"level" : {
"type" : "integer"
},
"order" : {
"type" : "integer"
},
"value" : {
"type" : "string",
"index" : "not_analyzed"
}
}
},
"id" : {
"type" : "integer"
},
"name" : {
"type" : "string",
"index" : "not_analyzed"
},
"role" : {
"type" : "nested",
"properties" : {
"name" : {
"type" : "string",
"index" : "not_analyzed"
}
}
}
}
},
}
}
}
}
}
设定:
{
"dev.directory.11" : {
"settings" : {
"index" : {
"creation_date" : "1483021523850",
"analysis" : {
"filter" : {
"word_delimiter" : {
"split_on_numerics" : "false",
"generate_word_parts" : "true",
"preserve_original" : "true",
"generate_number_parts" : "true",
"catenate_all" : "true",
"split_on_case_change" : "true",
"type" : "word_delimiter",
"catenate_numbers" : "true"
}
},
"analyzer" : {
"default" : {
"filter" : [ "lowercase", "word_delimiter" ],
"char_filter" : [ "html_strip", "replace" ],
"type" : "custom",
"tokenizer" : "whitespace"
}
},
"char_filter" : {
"replace" : {
"type" : "mapping",
"mappings" : [ "&=> and " ]
}
}
},
"number_of_shards" : "5",
"number_of_replicas" : "0",
"uuid" : "OrXHzHbtSI-vZAB01ckcEg",
"version" : {
"created" : "2030299"
}
}
}
}
}