You need to log in to create posts and topics.

Elasticsearch Cheat Sheet

All the API endpoints and pro-tips you always forgot about in one place!


There are two syntaxes for the basic queries: a simple one, where you can't use any option, and an extended one. Most of the beginner headache with the DSL come from this:

GET _search

{"query": {"match": {"FIELD": "TEXT"}}}


GET _search { "query": { "match": { "FIELD": { "query": "TEXT", "OPTION": "VALUE" } } } }


Common queries


"bool": { "must": [], "must_not": [], "filter": [], "should": [], "minimum_should_match" : 1 }



QueryString syntax recap

Search in the default _all field:

GET /_search?q=pony


Complex search with operator and exact phrase search with boost:

GET /_search?q=title:(joli OR code) AND author:"Damien Alexandre"^2


Search with wildcard and special queries:

GET /_search?q=_exists_:title OR title:singl? noneOrAnyChar*cter


Search with fuzzyness and range:

GET /_search?q=title:elastichurch~3 AND date:[2016-01-01 TO 2018-12-31]


Use in Query DSL (not recommended for user search):

GET /_search {"query":{"query_string":{"default_field":"content","query":"elastic AND (title:lucene OR title:solr)"}}}


Indexes and mapping

Create an index with settings and mapping

PUT /my_index_name {"settings":{"number_of_replicas":1,"number_of_shards":3,"analysis":{},"refresh_interval":"1s"},"mappings":{"my_type_name":{"properties":{"title":{"type":"text","analyzer":"english"}}}}}

Update index settings dynamically

PUT /my_index_name/_settings {"index":{"refresh_interval":"-1","number_of_replicas":0}}

Update an index by adding a field to a type

PUT /my_index_name/_mapping/my_type_name {"my_type_name":{"properties":{"tag":{"type":"keyword"}}}}

Get the mapping and the settings

GET /my_index_name/_mapping

GET /my_index_name/_settings

Create a document (auto-generated ID)

POST /my_index_name/my_type_name {"title":"Elastic is funny","tag":["lucene"]}

Create or update a document

PUT /my_index_name/my_type_name/12abc {"title":"Elastic is funny","tag":["lucene"]}

Delete a document

DELETE /my_index_name/my_type_name/12abc

Open and close indexes to save memory and CPU

POST /my_index_name/_close

POST /my_index_name/_open

Remove and create aliases

POST /_aliases {"actions":[{"remove":{"index":"my_index_name","alias":"foo"}},{"add":{"index":"my_index_name","alias":"bar","filter":{"term":{"user":"damien"}}}}]}

List aliases

GET /_aliases

GET /my_index_name/_alias/*

GET /*/_alias/*

GET /*/_alias/foo

Full custom analyzer declaration

PUT /english_example {"settings":{"analysis":{"filter":{"english_stop":{"type":"stop","stopwords":"_english_"},"english_stemmer":{"type":"stemmer","language":"english"}},"analyzer":{"my_english":{"char_filter":["html_strip"],"tokenizer":"standard","filter":["lowercase","english_stop","english_stemmer"]}}}}}