Created
June 27, 2016 15:41
-
-
Save marija17/1a7506cb3ec18ebdba1e87d8225d0bdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add a single document | |
PUT /vehicle/car/car1 | |
{ | |
"color": "red", | |
"make": "Saturn", | |
"year": 2005 | |
} | |
# Add more using bulk ... | |
POST /vehicle/car/_bulk | |
{ "index": {}} | |
{ "color" : "red", "make" : "Honda", "year" : "2005" } | |
{ "index": {}} | |
{ "color" : "black", "make" : "Honda", "year" : "2007" } | |
{ "index": {}} | |
{ "color" : "blue", "make" : "Honda", "year" : "2012" } | |
{ "index": {}} | |
{ "color" : "red", "make" : "Saturn", "year" : "2001" } | |
{ "index": {}} | |
{ "color" : "red", "make" : "Toyota", "year" : "2012" } | |
{ "index": {}} | |
{ "color" : "white", "make" : "Toyota", "year" : "2007" } | |
{ "index": {}} | |
{ "color" : "blue", "make" : "Ford", "year" : "2007" } | |
# Get everything ... | |
GET /vehicle/car/_search | |
# Aggregations | |
GET /vehicle/car/_search | |
{ | |
"query": { | |
"constant_score": { | |
"filter": { | |
"and": [ | |
{ | |
"terms": { | |
"make": [ | |
"honda", | |
"saturn" | |
] | |
} | |
}, | |
{ | |
"term": { | |
"color": "red" | |
} | |
} | |
] | |
} | |
} | |
}, | |
"aggs": { | |
"_": { | |
"global": {}, | |
"aggs": { | |
"_": { | |
"filter": { | |
"terms": { | |
"make": [ | |
"honda", | |
"saturn" | |
] | |
} | |
}, | |
"aggs": { | |
"color": { | |
"terms": { | |
"field": "color" | |
} | |
} | |
} | |
} | |
} | |
}, | |
"all_makes": { | |
"global": {}, | |
"aggs": { | |
"matches_other_filters": { | |
"filter": { | |
"terms": { | |
"color": [ | |
"red" | |
] | |
} | |
}, | |
"aggs": { | |
"make": { | |
"terms": { | |
"field": "make" | |
} | |
} | |
} | |
} | |
} | |
}, | |
"all_years": { | |
"global": {}, | |
"aggs": { | |
"matches_other_filters": { | |
"filter": { | |
"and": [ | |
{ | |
"terms": { | |
"make": [ | |
"honda", | |
"saturn" | |
] | |
} | |
}, | |
{ | |
"term": { | |
"color": "red" | |
} | |
} | |
] | |
}, | |
"aggs": { | |
"make": { | |
"terms": { | |
"field": "year" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment