Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save divideby0/5dd8445b157103fabfccdc1233b74209 to your computer and use it in GitHub Desktop.
Save divideby0/5dd8445b157103fabfccdc1233b74209 to your computer and use it in GitHub Desktop.
# Create a few vehicles with different types
POST /vehicles_type_agg_test/_bulk
{"index":{"_id":"honda_civic","_type": "car"}}
{"make": "Honda", "model": "Civic"}
{"index":{"_id":"honda_accord","_type": "car"}}
{"make": "Honda", "model": "Accord"}
{"index":{"_id":"tesla_roadster","_type": "car"}}
{"make":"Tesla", "model": "Roadster"}
{"index":{"_id":"audi_a4","_type": "car"}}
{"make":"Audi", "model": "A4"}
{"index":{"_id":"bmw_f_650_gs","_type": "motorcycle"}}
{"make": "BMW", "model": "F 650 GS"}
{"index":{"_id":"honda_anf125i_innova","_type": "motorcycle"}}
{"make":"Honda", "model": "ANF125i Innova"}
# Count vehicles by _type (you cannot use ?type=count for this)
GET /vehicles_type_agg_test/_search
{
"size": 0,
"aggs": {
"type": {
"terms": {
"field": "_type"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment