Hello, all
I have a query which group by groupId
.
{
"aggs":{
"result":{
"terms":{
"field":"groupId",
"size": 100
}
}
},
"size": 0
}
Because the index contains more than 100 million documents, and groupId
is a high-cardinality field, it is very slow.
But I added a filter in the query, like:
{
"aggs":{
"result":{
"terms":{
"field":"groupId",
"size": 100
}
}
},
"query":{
"terms":{
"groupId":["aaaaaaaaa","bbbbbbbbb","ccccccccc"]
}
},
"size": 0
}
or
{
"aggs":{
"filter_by_group":{
"filter":{
"terms":{
"groupId":["aaaaaaaaa","bbbbbbbbb","ccccccccc"]
}
},
"aggs":{
"result":{
"terms":{
"field":"groupId",
"size": 100
}
}
}
},
"size": 0
}
It seems to have no effect.
- How to achieve by query DSL?
- How to define the data scope of terms aggregation?
Please give some suggestions to improve performance.
Thanks.