Skip to content

Instantly share code, notes, and snippets.

@st
Last active March 19, 2018 15:30
Show Gist options
  • Save st/a9eb3c49135799149b754555fbeb8a0c to your computer and use it in GitHub Desktop.
Save st/a9eb3c49135799149b754555fbeb8a0c to your computer and use it in GitHub Desktop.
Elastic useful commands
# Elastic search version
curl 'localhost:9200'
# List all indices
$ curl 'localhost:9200/_cat/indices?v'
# this shows the status
# e.g:
# health status index pri rep docs.count docs.deleted store.size pri.store.size
#  close .kibana
# green open resources-index 3 0 20416 0 7.7mb 7.7mb
# open / close an index
curl -X POST 'localhost:9200/.kibana/_open'
curl -X POST 'localhost:9200/.kibana/_close'
# returns {"acknowledged":true}
# Count documents of a given type
$ curl 'localhost:9200/resources-index/usage-record/_count?pretty=true'
# returns
# {
# "count" : 1835608,
# "_shards" : {
# "total" : 3,
# "successful" : 3,
# "failed" : 0
# }
#}
# Delete all documents of specific type in index
$ curl -X POST 'http://localhost:9200/index/type/_delete_by_query' -d '{"query" : { "match_all" : {}}}'
# show all documents of a given type
# this will show all service-offer
curl 'localhost:9200/resources-index/service-offer/_search?pretty=true'
# query with separate json
curl -XGET 'localhost:9200/resources-index/service-offer/_search?pretty=true' -d@query.json
with query.json :
{
"query": {
"match": {
"connector.href": "open-telekom-de1"
}
}
}
# Note the double quotes around schema-org:name attribute
curl 'http://localhost:9200/resources-index/service-offer/_search?q="schema-org:name"="t2.small"&pretty=true'
# TAKE CARE, by default results are truncated to 10 because of size parameter
curl 'http://localhost:9200/resources-index/service-offer/_search?size=100&q="connector.href"="aws-us-east-1"&pretty=true' | grep "service-offer/" | wc -l
# View all backups
$ curl 'localhost:9200/_cat/snapshots/es_backup?v
# Edit a document
$ curl -X POST http://localhost:9200/resources-index/usage/99873571-0532-427d-9c60-bf66008d4123/_update -d '{"doc" : { "frequency" : "XXX"}}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment