我有一个具有以下结构的索引。
{
"title": "Your top FIY tips",
"content": "Fix It Yourself in April 2012.",
"tags": [
{
"tagName": "Fix it yourself"
},
{
"tagName": "customer tips"
},
{
"tagName": "competition"
}
]
}
映射看起来像
{
"articles": {
"mappings": {
"article": {
"properties": {
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"tags": {
"type": "nested",
"properties": {
"tagName": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
}
}
}
我正在使用以下 DSL 查询来搜索“内容”和“标题”字段,并将结果缩小到某个“标签名称”。然后使用聚合来计算该查询中的 tagNames。
GET /articles/_search
{
"from": 1,
"size": 10,
"aggs": {
"tags": {
"nested": {
"path": "tags"
},
"aggs": {
"tags-tagnames": {
"terms": {
"field": "tags.tagName.raw"
}
}
}
}
},
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "FIY",
"fields": [
"title",
"content"
]
}
},
{
"nested": {
"query": {
"terms": {
"tags.tagName": [
"competition"
]
}
},
"path": "tags"
}
}
]
}
}
}
“tagNames”的搜索查询和过滤器工作正常。然而,聚合并不完全有效。它似乎没有在结果中包含嵌套查询数据。返回的聚合结果只是基于多匹配搜索。
如何在聚合中包含嵌套查询。
样本文件在
https://gist.github.com/anonymous/83bc2b1bfa0ac0d295d42297e1d76c00