[英]Elasticsearch aggregations on array
I have an array: 我有一个数组:
people: ["Darrell","Karen","Gary"]
Indexed as such: 索引如下:
indexes :people, type: 'string', include_in_all: false
I want to be able to search aggregations on the individual items in this array, but with this structure, a search for "Darrel" will also return "Karen" and "Gary" in the bucket results. 我希望能够搜索此数组中各个项目的聚合,但是使用此结构,搜索“ Darrel”还将在存储桶结果中返回“ Karen”和“ Gary”。 And a search for "Karen" will not return any of the items in the array in the results.
搜索“ Karen”将不会在结果中返回数组中的任何项目。
There are some suggestions here http://coderify.com/aggregates-array-field-and-autocomplete-funcionality-in-elasticsearch/ , but I'm not able to change my structure in this way. 这里有一些建议http://coderify.com/aggregates-array-field-and-autocomplete-funcionality-in-elasticsearch/ ,但是我无法以这种方式更改结构。 Any other suggestions?
还有其他建议吗?
You need to use nested aggregation and filter aggregation to achieve this. 您需要使用嵌套聚合和过滤器聚合来实现此目的。
But before that , you might need to remodel your data as following 但在此之前,您可能需要按以下方式重塑数据
{
"people": [
{
"name": "Darrell"
},
{
"name": "Karen"
},
{
"name": "Gary"
}
]
}
Next make the field people as nested in the mapping. 接下来,使现场人员嵌套在映射中。 Now each people inner object would be treated as a inner document.
现在,每个人的内部对象都将被视为内部文档。
Now use the following aggregation to get what you need - 现在,使用以下聚合来获取所需的信息-
{
"aggs": {
"innerDOcuments": {
"nested": {
"path": "people"
},
"aggs": {
"filterPeople": {
"filter": {
"name": "karen"
},
"aggs": {
"peoples": {
"terms": {
"field": "name"
}
}
}
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.