Last active
March 14, 2021 09:01
-
-
Save gscattolin/23080b3a0f40695e840ed958bb0ac414 to your computer and use it in GitHub Desktop.
Elastic search most common curls
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
curl 'localhost:9200/_cat/indices?v' => list of index | |
curl 'localhost:9200/_cluster/health?pretty' => health | |
curl -XGET 'http://localhost:9200/_mapping/twitter' => map of index twitter | |
curl -XPOST 'localhost:9200/bank/_search?pretty' -d ' | |
{ | |
"size": 0, | |
"aggs": { | |
"group_by_state": { | |
"terms": { | |
"field": "state" | |
} | |
} | |
} | |
}' | |
///search in a date range | |
{ | |
"query": { | |
"filtered": { | |
"query": { | |
"match_all": {} | |
}, | |
"filter": { | |
"range": { | |
"createdTime": { | |
"gte": "2016-04-17 00:00:00", | |
"lte" : "2016-10-09 00:00:00" | |
} | |
} | |
} | |
} | |
} | |
} | |
// search wildcards | |
{ | |
"_source": ["json.servlet","json.method","json.path"], | |
"size" : 200, | |
"query": { | |
"bool": { | |
"must": [ | |
{"wildcard": { | |
"json.path": "toke*"}}, | |
{"match": { | |
"json.method": "POST"}}] | |
} | |
} | |
} | |
// query boolean + sort | |
{ | |
"query": { | |
"bool": { | |
"must_not": [ | |
{ | |
"term": { | |
"extension": ".csv" | |
} | |
}, | |
{ | |
"term": { | |
"extension": ".xlsx" | |
} | |
} | |
], | |
"must": { | |
"missing": { | |
"field": "bucket" | |
} | |
} | |
} | |
}, | |
"sort": [ | |
{ | |
"length": { | |
"order": "desc" | |
} | |
} | |
], | |
"from": 0, | |
"size": 40 | |
} | |
// query boolean + aggregation | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"term": { | |
"extension": ".csv" | |
} | |
} | |
] | |
} | |
}, | |
"aggs": { | |
"TotalSize": { | |
"sum": { | |
"field": "length" | |
} | |
} | |
} | |
} | |
//search filter+query | |
GET /megacorp/employee/_search | |
{ | |
"query" : { | |
"filtered" : { | |
"filter" : { | |
"range" : { | |
"age" : { "gt" : 30 } | |
} | |
}, | |
"query" : { | |
"match" : { | |
"last_name" : "smith" | |
} | |
} | |
} | |
} | |
} | |
//aggregation with histogram | |
GET /_search | |
{ | |
"size": 0, | |
"aggs": { | |
"my_buckets": { | |
"composite": { | |
"sources": [ | |
{ "histo": { "histogram": { "field": "price", "interval": 5 } } } | |
] | |
} | |
} | |
} | |
} | |
GET /_search | |
{ | |
"size": 0, | |
"aggs": { | |
"my_buckets": { | |
"composite": { | |
"sources": [ | |
{ | |
"date": { | |
"date_histogram": { | |
"field": "timestamp", | |
"calendar_interval": "1d", | |
"format": "yyyy-MM-dd" | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment