Elasticsearch aggregate query

Elasticsearch is an open source distributed search and analysis engine that provides rich aggregation query functionality. Here are some common aggregation queries and examples: 1. Conditional Filter Aggregation Query: Aggregates data based on specified filtering conditions, returning only results that meet the conditions. json GET /products/_search { "size": 0, "aggs": { "filtered_data": { "filter": { "term": { "category": "electronics" } }, "aggs": { "avg_price": { "avg": { "field": "price" } } } } } } The above example will aggregate and return the average price of all products with the category "electronics". 2. Range Aggregation Query: Aggregates data based on a specified numerical range. json GET /products/_search { "size": 0, "aggs": { "price_ranges": { "range": { "field": "price", "ranges": [ { "to": 100 }, { "from": 100, "to": 500 }, { "from": 500 } ] } } } } The above example will aggregate and return the quantity of products with prices within different ranges. 3. Histogram Aggregation Query: Aggregates data based on specified numerical intervals. json GET /products/_search { "size": 0, "aggs": { "price_histogram": { "histogram": { "field": "price", "interval": 100 } } } } The above example will aggregate and return a price histogram with intervals of 100. 4. Date Histogram Aggregation Query: Aggregates data based on specified date intervals. json GET /products/_search { "size": 0, "aggs": { "date_histogram": { "date_histogram": { "field": "date", "calendar_interval": "month" } } } } The above example will aggregate and return the number of products per month. 5. Terms Aggregation Query: Group based on specified fields and perform aggregation calculations on each group. json GET /products/_search { "size": 0, "aggs": { "group_by_category": { "terms": { "field": "category" }, "aggs": { "avg_price": { "avg": { "field": "price" } } } } } } The above example will aggregate and return the quantity of products grouped by category, and calculate the average price for each category. This only demonstrates a small portion of the Elasticsearch aggregation query functionality, but there are actually many other aggregation query types and available parameters for selection and use. The specific table structure and sample data need to be determined based on the application scenario.