Skip to content

Instantly share code, notes, and snippets.

@hectorcanto
Last active July 12, 2019 10:45
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 hectorcanto/605797d789fbbacb6cf34b7930933ab5 to your computer and use it in GitHub Desktop.
Save hectorcanto/605797d789fbbacb6cf34b7930933ab5 to your computer and use it in GitHub Desktop.
[Elastic commands] Some recurrent Elastic commands #elasticsearch #kibana
# Get all indices, verbose
GET /_cat/indices?v
# Create an index with a mapping
PUT index
{
"mappings": {
"_doc": {
"properties": {
"field": {
"type": "boolean"
},
}
}
}
# Delete an index
DELETE index
# Clone an index, create the new index with the same mapping first
POST _reindex
{
"source": {
"index": "original"
},
"dest": {
"index": "destination"
}
}
# All documents in an Index, use size if you want to get more elements
GET /index/_doc/_search
{
"size": 100,
"query": {
"match_all": {}
}
}
#Get a single doc
GET /index/_doc/$_ID
# Single partial update
POST /index/_doc/{_id}/_update
{ "doc": {"field": "new_value"} }
#Bulk partial update
POST /index/_bulk
{"update" : {"_id" : "122", "_type" : "_doc"}}
{"doc" : {"field" : "new_value"}}
#Ranged query with selected fields, for dates use ISOFORMAT with Zulu ending
GET /index/_search
{
"_source": ["date", "name", "other_field"],
"query": {
"range": {"date": {"gte": "2019-06-15", "lte": "2019-06-28"}}}
}
# Search with regexp
GET /index/_doc/_search
{
"query": {
"regexp": {
"field": "(.*[a-zA-Z].*)"
}
}
}
#Search with Wildcard
GET /index/_doc/_search
{
"query": {
"wildcard": {"field": "*text*"}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment