Elasticsearch – Advance Query [Aggregations]

The from and size is almost like pagination. It will show 0 to 20 results.The sort is sorting the return data. What is happening here, it will use the query and fetch method. It will query it and get the data and then limit the data based on the given from and size parameter.

Counting the given result.

Basic aggregation, popular_cars is an alias. This is shown how many documents do we have based on the field name. The reason behind using the make keyword, because the datatype for make is a text datatype. And in elasticsearch text is put in an inverted index. Aggregations are good for values, not free-formed text. So it won’t work if we only use the make field, we need to specify that we need to convert it into a keyword, so elasticsearch consider it as one whole word

We need to get an average price for each car type. Like the average “dodge” price.

In here we are getting max and min price also.

Running stats on a specific field of data.

Using range in aggregation to determine who many cars we sold in the given year range.

The average price for each time span declared in query, i.e. year range sold car average price.