我在弹性弹性搜索中有数百个文档,其中一个字段名为 ner_new
,该字段包含 unique_words
列表及其 entity_type
. 数据如下所示:
"_source": {
"ner_new": [
{
"entities": [
{
"entity_type": "Location",
"unique_word": "Fashion Show Jenahara"
},
{
"entity_type": "Person",
"unique_word": "Jakarta"
},
{
"entity_type": "Organization",
"unique_word": "Fashion Festival"
}
],
},
}
我想计算 unique_word
与 entity_type
"Person"出现在所有文件中的次数 . 它就像Person的名字摘要 . 这是我目前的查询:
{
"query": {
"match": {
"ner_new.entities.entity_type": "Person"
}
},
"aggs" : {
"Person" : {
"filter" : { "match": { "ner_new.entities.entity_type": "Person" } },
"aggs" : {
"word" : { "terms" : { "field" : "ner_new.entities.unique_word" } }
}
}
}
}
这个聚合代码的结果是:
"aggregations": {
"Person": {
"doc_count": 1127,
"word": {
"doc_count_error_upper_bound": 39,
"sum_other_doc_count": 15270,
"buckets": [
{
"key": "Jakarta",
"doc_count": 331
},
{
"key": "Indonesia",
"doc_count": 295
},
...
}
聚合的过滤器设法计算属于Person类型的 unique_word
,但是,当我想显示数据时,它会显示所有 unique_word
,甚至是不在Person类型中的 unique_word
.
我用代码做错了吗?请帮忙 . 谢谢