# Elastic search cheat sheet #### GET data GET http://localhost:9200/:index/:type/:id #### PUT (or update) data PUT http://localhost:9200/:index/:type/(:id) #### Check data existence HEAD localhost:9200/:index/:type/:id #### DELETE data # All resources DELETE http://localhost:9200/_all # An index DELETE http://localhost:9200/:index # A type DELETE http://localhost:9200/:index/:type # An item DELETE http://localhost:9200/:index/:type/:id #### Searching The `hits` object gives you the top 10 hits that matched the query. The `score` represents how well the results matched the query. # Empty searches # Entire database GET http://localhost:9200/_search # One index GET http://localhost:9200/:index/_search # Multuple indecies GET http://localhost:9200/:index,:index/_search # Wildcards GET http://localhost:9200/hub*/_search ##### Pagination # Page 1 GET http://localhost:9200/_search?size=5&from=0 # Page 2 GET http://localhost:9200/_search?size=5&from=5 ##### On fields Good for development, not for production. If you do not specify a field, elasticsearch automatically uses the `_all` field, which searches through all fields. GET /_search?q:fieldName:query #### Datatype mapping When you insert data into elastic search, it uses dynamic detection to determine what kind of data each field is. ##### Get mapping GET http://localhost:9200/:index/:type/_mapping ##### Changing mapping * If you are adding fields, there is no need to reindex. * If you need to change a field, you need to reindex your data. [An article on the subject](http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/) ##### Reindex data **Lookup more detailed information on how to do this** * Create a new index with the new mapping (see PUT mapping below) * Pull in documents from the old index using a [scrolled search](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-scroll.html) and index them to the new index using the [bulk API](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html). Note: make sure that you include search_type=scan in your search request. This disables sorting and makes "deep paging" efficient. * Update [index alias](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html). * Delete the old index ##### PUT (or update) mapping PUT http://localhost:9200/:index/:type -d '{ "mappings": { "tweet": { "properties": { … } } } }'