Skip to content

Instantly share code, notes, and snippets.

@hhimanshu
Created August 25, 2015 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhimanshu/a4e84ed266bedd337541 to your computer and use it in GitHub Desktop.
Save hhimanshu/a4e84ed266bedd337541 to your computer and use it in GitHub Desktop.
ElasticSearch: The definitive guide
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