{"info":{"_postman_id":"212714f5-f2f7-4b78-8042-05ed978725a0","name":"5 simple examples to understand ES aggregation","schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json"},"item":[{"name":"Aggregation - Bulk Insert documents","_postman_id":"2dade8f1-ca4c-4a48-8fb9-75510d570d5e","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/x-ndjson"}],"body":{"mode":"raw","raw":"{ \"index\" : { \"_index\" : \"cars\", \"_type\" : \"_doc\", \"_id\" : \"1\" } }\n{ \"manufacturer\" : \"Audi\", \"model\" : \"A6\", \"price\" : 3900000, \"sold_date\" : \"2020-03-10\" }\n\n{ \"index\" : { \"_index\" : \"cars\", \"_type\" : \"_doc\", \"_id\" : \"2\" } }\n{ \"manufacturer\" : \"Ford\", \"model\" : \"Fiesta\", \"price\" : 580000, \"sold_date\" : \"2020-07-18\" }\n\n{ \"index\" : { \"_index\" : \"cars\", \"_type\" : \"_doc\", \"_id\" : \"3\" } }\n{ \"manufacturer\" : \"Audi\", \"model\" : \"A7\", \"price\" : 6500000, \"sold_date\" : \"2020-05-28\" }\n\n{ \"index\" : { \"_index\" : \"cars\", \"_type\" : \"_doc\", \"_id\" : \"4\" } }\n{ \"manufacturer\" : \"Audi\", \"model\" : \"A8\", \"price\" : 14900000, \"sold_date\" : \"2020-06-10\" }\n\n{ \"index\" : { \"_index\" : \"cars\", \"_type\" : \"_doc\", \"_id\" : \"5\" } }\n{ \"manufacturer\" : \"Ford\", \"model\" : \"Linea\", \"price\" : 420000, \"sold_date\" : \"2020-05-26\" }\n\n{ \"index\" : { \"_index\" : \"cars\", \"_type\" : \"_doc\", \"_id\" : \"6\" } }\n{ \"manufacturer\" : \"Ford\", \"model\" : \"Figo\", \"price\" : 480000, \"sold_date\" : \"2020-07-13\" }\n\n{ \"index\" : { \"_index\" : \"cars\", \"_type\" : \"_doc\", \"_id\" : \"7\" } }\n{ \"manufacturer\" : \"Maruti\", \"model\" : \"Swift\", \"price\" : 680000, \"sold_date\" : \"2020-05-25\" }\n\n{ \"index\" : { \"_index\" : \"cars\", \"_type\" : \"_doc\", \"_id\" : \"8\" } }\n{ \"manufacturer\" : \"Tata\", \"model\" : \"Nexon\", \"price\" : 880000, \"sold_date\" : \"2020-05-25\" }\n\n\n{ \"index\" : { \"_index\" : \"cars\", \"_type\" : \"_doc\", \"_id\" : \"8\" } }\n{ \"manufacturer\" : \"Tata\", \"model\" : \"Altroz\", \"price\" : 680000, \"sold_date\" : \"2020-03-25\" }\n\n\n{ \"index\" : { \"_index\" : \"cars\", \"_type\" : \"_doc\", \"_id\" : \"9\" } }\n{ \"manufacturer\" : \"Tata\", \"model\" : \"Tigor\", \"price\" : 520000, \"sold_date\" : \"2020-07-25\" }\n"},"url":"http://localhost:9200/cars/_doc/_bulk"},"response":[]},{"name":"Aggregation - What is the average price of all sold cars which have manufacturer Audi ?","_postman_id":"1fe4c4fb-f7e1-41d5-8e8b-cfa00cf2ddea","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n    \"size\": 0,\n    \"query\" : {\n      \"match\": {\n        \"manufacturer\": \"audi\"\n      }\n    }, \n    \"aggs\": {\n      \"average_price\": {\n        \"avg\": {\n          \"field\": \"price\"\n        }\n      }\n    }\n}"},"url":{"raw":"http://localhost:9200/cars/_search?pretty","protocol":"http","host":["localhost"],"port":"9200","path":["cars","_search"],"query":[{"key":"pretty","value":null}]}},"response":[]},{"name":"Aggregation - Find all cars made by Ford and average price of only those cars sold in Jul 2020","_postman_id":"66e381ed-be01-47e4-a368-0c3d10b37984","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"query\": {\n    \"match\": {\n      \"manufacturer\": \"ford\"\n    }\n  },\n  \"aggs\": {\n    \"recent_sales\": {\n      \"filter\": {\n        \"range\": {\n          \"sold_date\": {\n            \"gte\": \"2020-07-01\", \n            \"lte\": \"2020-07-31\"\n          }\n        }\n      },\n      \"aggs\": {\n        \"average_price\": {\n          \"avg\": {\n            \"field\": \"price\"\n          }\n        }\n      }\n    }\n  }\n}"},"url":{"raw":"http://localhost:9200/cars/_search?pretty","protocol":"http","host":["localhost"],"port":"9200","path":["cars","_search"],"query":[{"key":"pretty","value":null}]}},"response":[]},{"name":"Aggregation - What is the total price of all cars sold in Jul 2020 ?","_postman_id":"c7f4bb96-ab01-4f47-9bf1-9d6fc8198dcd","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n    \"size\": 0,\n    \"query\" : {\n      \"range\": {\n        \"sold_date\": {\n          \"gte\": \"2020-07-01\",\n          \"lte\": \"2020-07-31\"\n        }\n      }\n    },\n    \"aggs\": {\n      \"total_price\": {\n        \"sum\": {\n          \"field\": \"price\"\n        }\n      }\n    }\n}"},"url":{"raw":"http://localhost:9200/cars/_search?pretty","protocol":"http","host":["localhost"],"port":"9200","path":["cars","_search"],"query":[{"key":"pretty","value":null}]}},"response":[]},{"name":"Aggregation - Which are the most popular car manufacturers?","_postman_id":"b73303f9-23f0-43da-ab27-06c2f61b6cac","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"size\": 0,\n  \"query\": {\n    \"range\": {\n      \"sold_date\": {\n        \"from\": \"now-3M\"\n      }\n    }\n  },\n  \"aggs\": {\n    \"group_by_make\": {\n      \"terms\": {\n        \"field\": \"manufacturer.keyword\"\n      }\n    }\n  }\n}"},"url":{"raw":"http://localhost:9200/cars/_search?pretty","protocol":"http","host":["localhost"],"port":"9200","path":["cars","_search"],"query":[{"key":"pretty","value":null}]}},"response":[]},{"name":"Aggregation - How much sales were made each month ?","_postman_id":"87c32589-5c2c-4dc2-a449-50e2872fd81c","request":{"method":"POST","header":[{"key":"Content-Type","value":"application/json"}],"body":{"mode":"raw","raw":"{\n  \"size\": 0,\n  \"aggs\": {\n    \"sales_over_time\": {\n      \"date_histogram\": {\n        \"field\": \"sold_date\",\n        \"interval\": \"month\",\n        \"format\" : \"MM-yyyy\"\n      },\n      \"aggs\": {\n        \"monthly_sales\": {\n          \"sum\": {\n            \"field\": \"price\"\n          }\n        }\n      }\n    }\n  }\n}"},"url":{"raw":"http://localhost:9200/cars/_search?pretty","protocol":"http","host":["localhost"],"port":"9200","path":["cars","_search"],"query":[{"key":"pretty","value":null}]}},"response":[]}],"protocolProfileBehavior":{}}