A quick reference to Elasticsearch.
Created on: 2019-01-22
Tag: cheat_sheet
Words wrapped with curly braces, like {host} are variable, replace them with appropriate value.
To list all the indexes of an Elasticsearch instance run the following command 1:
curl -XGET "http://{host}:{port}/_cat/indices?v"
To create a new index run the following command 2:
curl -XPUT 'http://{host}:{port}/{index}?pretty&pretty'
To delete an index run the following command 3:
curl -XDELETE 'http://{host}:{port}/{index}?pretty&pretty'
To upload a single data to an index run the following command 4:
curl -XPUT 'http://{host}:{port}/{index}/{type}/{doc_id}?pretty&pretty' -H 'Content-Type: application/json' -d' { "field_name": "data" }'
To update a single data field run the following command 5:
curl -XPOST 'http://{host}:{port}/{index}/{type}/{doc_id}/_update?pretty&pretty' -H 'Content-Type: application/json' -d' { "doc": { "field_name": "data" } }' OR curl -XPOST 'http://{host}:{port}/{index}/{type}/{doc_id}/_update?pretty&pretty' -H 'Content-Type: application/json' -d' { "script" : "ctx._source.field_name += 1" }'
To search and index run the following command 6:
curl -XGET 'http://{host}:{port}/{index}/_search?q={field_name}:{keyword}'
To delete only the data of an index run the following command 7:
curl -X POST "http://{host}:{port}/{index}/{type}/_delete_by_query?conflicts=proceed" -H 'Content-Type: application/json' -d' { "query": { "match_all": {} } } '