Elasticsearch generals
This article introduces general concept of Elastic search.
ElasticSearch is a distributed, open-source search and analytics engine built on Apache lucene
Common APIs
Elasticsearch exposes a RESTful HTTP API.
Document APIs
POST /{index}/_docindex a documentGET /{index}/_doc/{id}get a documentDELETE /{index}/_doc/{id}delete a documentPOST /{index}/_update/{id}update a documentPOST /{index}/_bulkexecute bulk operationsGET /{index}/_countcount documents in an indexGET /{index}/_searchsearch documentsPOST /{index}/_searchsearch with a request bodyPOST /_msearchmulti-search across one or more indicesPOST /_update_by_queryupdate matching documents by queryPOST /_delete_by_querydelete matching documents by queryGET /{index}/_termvectorsretrieve term vectors for a document
Index APIs
PUT /{index}create an indexDELETE /{index}delete an indexGET /{index}get index informationHEAD /{index}check whether an index existsGET /{index}/_mappingget index mappingPUT /{index}/_mappingupdate index mappingGET /{index}/_settingsget index settingsPUT /{index}/_settingsupdate index settingsPOST /{index}/_refreshrefresh indexPOST /{index}/_flushflush indexPOST /{index}/_forcemergeforce merge index segmentsPOST /{index}/_openopen an indexPOST /{index}/_closeclose an index
Cluster APIs
GET /_cluster/healthget cluster healthGET /_cluster/statsget cluster metricsGET /_cluster/stateget cluster stateGET /_cluster/settingsget cluster settingsPUT /_cluster/settingsupdate cluster settingsGET /_nodesget node informationGET /_nodes/statsget node statisticsGET /_nodes/hot_threadsshow hot threads on nodesGET /_cluster/pending_taskslist pending cluster tasks
Cat APIs
GET /_cat/health?vcluster health in a compact formatGET /_cat/indices?vlist indicesGET /_cat/nodes?vlist nodesGET /_cat/shards?vlist shardsGET /_cat/allocation?vshow shard allocationGET /_cat/recovery?vshow recovery statusGET /_cat/pending_tasks?vshow pending tasksGET /_cat/templates?vlist index templates
Snapshot and restore APIs
PUT /_snapshot/{repository}/{snapshot}create a snapshotGET /_snapshot/{repository}/{snapshot}get snapshot informationDELETE /_snapshot/{repository}/{snapshot}delete a snapshotPOST /_snapshot/{repository}/{snapshot}/_restorerestore a snapshot
Reindexing and scroll APIs
POST /_reindexcopy documents from one index to anotherGET /_search/scrollretrieve the next scroll pageDELETE /_search/scrollclear scroll contexts
Reference
Mapping
Schema definition specifying how document fields are stored and indexed in Elasticsearch.
search
Elasticsearch search requests use JSON bodies to specify query logic, pagination, sorting, aggregations, and result shaping. Common fields in the search JSON include:
query- selects documents.bool- combine clauses:must,should,must_not,filtermatch- full-text match on analyzed fieldsterm- exact value matchrange- numeric or date intervalsnested- queries inside nested object fieldsexists- field presence
aggs/aggregations- summarize matching documents.- bucket aggs:
terms,range,date_histogram,histogram,filters - metric aggs:
avg,sum,min,max,stats,cardinality,value_count
- bucket aggs:
size- hits per pagefrom- result offset for paginationsort- result ordering by field or score_source- which document fields to returnfields- stored/scripted field values to fetchhighlight- return matched snippetspost_filter- filter search hits after aggregationstimeout- time limit for the searchtrack_total_hits- accurate hit count controlexplain- return scoring explanation for each hittrack_scores- keep scores when sorting/pagingprofile- return query execution timingsearch_after- deep pagination cursor using sort valuescollapse- collapse results by a field valuesuggest- autocomplete or correction suggestionsscript_fields- compute extra fields per hit with scriptsrescore- rerank top hits with a second query
These fields can be combined to express complex search behavior.