Created
August 25, 2015 23:13
-
-
Save hhimanshu/a4e84ed266bedd337541 to your computer and use it in GitHub Desktop.
ElasticSearch: The definitive guide
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
GET _search | |
{ | |
"query": { | |
"match_all": {} | |
} | |
} | |
PUT /megacorp/employee/1 | |
{ | |
"first_name": "John", | |
"last_name": "Smith", | |
"age" : 25, | |
"about" : "I love to go rock climbing and swimming", | |
"interests": [ "sports", "music" ] | |
} | |
PUT /megacorp/employee/2 | |
{ | |
"first_name" : "Jane", | |
"last_name": "Smith", | |
"age" : 32, | |
"about" : "I like to collect rock albums", | |
"interests": [ "music" ] | |
} | |
PUT /megacorp/employee/3 | |
{ | |
"first_name" : "Douglas", | |
"last_name": "Fir", | |
"age" : 35, | |
"about": "I like to build cabinets", | |
"interests": [ "forestry" ] | |
} | |
GET /megacorp/employee/_search | |
GET /megacorp/employee/_search?q=last_name:Smith | |
GET /megacorp/employee/_search | |
{ | |
"query":{ | |
"match": { | |
"last_name": "Smith" | |
} | |
} | |
} | |
GET /megacorp/employee/_search | |
{ | |
"query": { | |
"filtered": { | |
"query": { | |
"match": { | |
"last_name": "Smith" | |
} | |
}, | |
"filter": { | |
"range": { | |
"age": { | |
"gt": 30 | |
} | |
} | |
} | |
} | |
} | |
} | |
GET /megacorp/employee/_search | |
{ | |
"query": { | |
"match": { | |
"about": "rock climbing" | |
} | |
} | |
} | |
GET /megacorp/employee/_search | |
{ | |
"query": { | |
"match_phrase": { | |
"about": "rock climbing" | |
} | |
} | |
} | |
GET /megacorp/employee/_search | |
{ | |
"query": { | |
"match_phrase": { | |
"about": "rock climbing" | |
} | |
}, | |
"highlight": { | |
"fields": { | |
"about": {} | |
} | |
} | |
} | |
GET /megacorp/employee/_search | |
{ | |
"aggs": { | |
"all_interests": { | |
"terms": { | |
"field": "interests" | |
} | |
} | |
} | |
} | |
GET /megacorp/employee/_search | |
{ | |
"query": { | |
"match": { | |
"last_name": "Smith" | |
} | |
}, | |
"aggs": { | |
"all_interests": { | |
"terms": { | |
"field": "interests" | |
} | |
} | |
} | |
} | |
GET /megacorp/employee/_search | |
{ | |
"aggs": { | |
"all_interests": { | |
"terms": { | |
"field": "interests" | |
}, | |
"aggs": { | |
"avg_age": { | |
"avg": { | |
"field": "age" | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment