Krrish Raj
Krrish Raj

Reputation: 1535

Applying custom filters for aggregation in Elastic Search

I have more that 2 million documents which has price and discount. I have to get percentage of products with 10%, 20%, 30%,......, 90%, 100% discount(discounts are rounded off). Its not possible to fetch data and aggregate it on application layer at it will take too much time. I am also afraid that it will create lag for other users as thread will be busy for a long time.

Is there any way I can create custom filters upon aggregation logic?

Upvotes: 0

Views: 100

Answers (1)

imotov
imotov

Reputation: 30163

It doesn't look like you need a custom filter here. This functionality is a standard part of the histogram aggregation. You can also take a look at the range aggregation in case you need more flexible ranges.

If you need a complete flexibility in how terms are calculated you can also use script in terms aggregation to return the value you want to group your records by. However, with 2 million documents, it might be better to pre-calculate the discount during before indexing the document, store this value as a separate field and then use histogram aggregation.

Upvotes: 3

Related Questions