How to speed up aggregated query?

I have the following query:
{'size': 0, 'aggs': {'count_group': {'filters': {'filters': {'89634469': {'term': {'supplier.id': 89634469}}, '89633422': {'term': {'supplier.id': 89633422}}}}, 'aggs': {'market': {'terms': {'field': 'supplier_nom.id', 'size': 100000}}}}}, 'query': {'bool': {'must': [{'has_parent': {'parent_type': 'doc', 'query': {'bool': {'must': [{'range': {'created': {'lte': 'now/d'}}}, {'range': {'expires': {'gte': 'now/d'}}}]}}}}, {'term': {'doc_type': 'item'}}]}}}
The result looks like this

It works well, but if I put a much more supplier.ids, It begin to works much slower. Any suggestions to improve speed?

You aggregation is pretty hard to read, so I may be wrong.

as you can see in the hits.total field, there are still 280k documents that need to be filtered for.

Can you create an additional filter terms query in the query to only filter for the ids that you are interested in? This would reduce the total number of documents, that you have to aggregate against and likely give you a speedup.

Thank you for your answer. Probably, i should clarify.


At existing approach, i put ids in filters field and then aggregate result through field supplier_nom.id. Then i have much more ids, i lose speed. Is there any way to reconstruct query in order to gain speed with the same logic?

please look at the term query I mentioned above.

How about composite aggregation?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.