有人可以帮助我获取弹性搜索中嵌套对象的聚合计数,假设我的弹性搜索对象映射为:
{
"employe": {
"dynamic": "strict",
"properties": {
"empId":{
"type": "keyword"
},
"entities": {
"type": "nested"
}
}
}
}
实体是带有其他对象的数组类型。我想获取过滤项目的实体数量。
我尝试过一些弹性搜索查询,但它不起作用
{
"query": {
"bool": {
"filter": [
{
"terms": {
"empId": [12121,2121212]
}
}
]
}
},
"size": 0,
"aggs": {
"entities_agg": {
"sum": {
"field": "entities",
"script": {
"inline": "doc['entities'].values.size()"
}
}
}
}
}
您无法通过文档值访问嵌套数据,您需要访问源文档,如下所示:
{
"query": {
"bool": {
"filter": [
{
"terms": {
"empId": [
12121,
2121212
]
}
}
]
}
},
"size": 0,
"aggs": {
"entities_agg": {
"sum": {
"script": {
"inline": "params._source.entities.size()"
}
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)