Skip to content

Instantly share code, notes, and snippets.

@viztastic
Last active October 3, 2016 01:38
Show Gist options
  • Save viztastic/25e2ad74a1f531e3a6af0d8be20f7b2d to your computer and use it in GitHub Desktop.
Save viztastic/25e2ad74a1f531e3a6af0d8be20f7b2d to your computer and use it in GitHub Desktop.
Quick notes to help me get my head around Elastic stack.

Elasticsearch

Cluster

Cluster Health

GET /_cat/health?v

Indices

Listing Indices

GET /_cat/indices?v

Creating Indices

PUT /{INDEX_NAME}?pretty

Documents

Creating document to index

PUT /{INDEX_NAME}/{TYPE}/{ID}/pretty

{
    "key" : "value"
}

Batch Uploading Documents

Uploading documents of a single type

POST /{INDEX_NAME}/{TYPE}/_bulk?pretty

{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }

Bulk Updating documents

This example updates the first document (ID of 1) and then deletes the second document (ID of 2) in one bulk operation:

POST /{INDEX_NAME}/{TYPE}/_bulk?pretty

{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}

Note above that for the delete action, there is no corresponding source document after it since deletes only require the ID of the document to be deleted.

Uploading documents of different types

POST localhost:9200/_bulk

{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "create" : { "_index" : "test", "_type" : "type1", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} }
{ "doc" : {"field2" : "value2"} }

Retreiving from the index

GET /{INDEX_NAME}/{TYPE}/{ID}?pretty

Updating Documents

POST /{INDEX_NAME}/{TYPE}/{ID}?pretty

{
   "doc" : { "name" : "Jane Doe" }
}

Deleting an index

DELETE /{INDEX_NAME}?pretty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment