
This is currently the default API, but with the upcoming release of Elasticsearch 1.0 that will change. We recommend setting the apiVersion
config param when you instantiate your client to make sure that the API does not change when the default does.
- bulk
- clearScroll
- count
- create
- delete
- deleteByQuery
- exists
- explain
- get
- getSource
- index
- info
- mget
- mlt
- msearch
- percolate
- ping
- scroll
- search
- suggest
- update
- cluster.getSettings
- cluster.health
- cluster.nodeHotThreads
- cluster.nodeInfo
- cluster.nodeShutdown
- cluster.nodeStats
- cluster.putSettings
- cluster.reroute
- cluster.state
- indices.analyze
- indices.clearCache
- indices.close
- indices.create
- indices.delete
- indices.deleteAlias
- indices.deleteMapping
- indices.deleteTemplate
- indices.deleteWarmer
- indices.exists
- indices.existsAlias
- indices.existsType
- indices.flush
- indices.getAlias
- indices.getAliases
- indices.getFieldMapping
- indices.getMapping
- indices.getSettings
- indices.getTemplate
- indices.getWarmer
- indices.open
- indices.optimize
- indices.putAlias
- indices.putMapping
- indices.putSettings
- indices.putTemplate
- indices.putWarmer
- indices.refresh
- indices.segments
- indices.snapshotIndex
- indices.stats
- indices.status
- indices.updateAliases
- indices.validateQuery
client.bulk([params, [callback]])
Perform many index/delete operations in a single API call.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Perform three operations in a single request.
client.bulk({ body: [ // action description { index: { _index: 'myindex', _type: 'mytype', _id: 1 } }, // the document to index { title: 'foo' }, // action description { update: { _index: 'myindex', _type: 'mytype', _id: 2 } }, // the document to update { doc: { title: 'foo' } }, // action description { delete: { _index: 'myindex', _type: 'mytype', _id: 3 } }, // no document needed for this delete ] }, function (err, resp) { // ... });
|
|
|
|
|
|
|
|
|
|
|
|
client.clearScroll([params, [callback]])
Clear the scroll request created by specifying the scroll parameter to search.
The default method is DELETE
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
client.count([params, [callback]])
Get the number of documents for the cluster, index, type, or a query.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Get the number of all documents in the cluster.
client.count(function (error, response, status) { // check for and handle error var count = response.count; });
Get the number of documents in an index.
client.count({ index: 'index_name' }, function (error, response) { // ... });
Get the number of documents matching a query.
client.count( index: 'index_name', body: { filtered: { filter: { terms: { foo: ['bar'] } } } } }, function (err, response) { // ... });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.create([params, [callback]])
Adds a typed JSON document in a specific index, making it searchable. If a document with the same index
, type
, and id
already exists, an error will occur.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Create a document.
client.create({ index: 'myindex', type: 'mytype', id: '1', body: { title: 'Test 1', tags: ['y', 'z'], published: true, published_at: '2013-01-01', counter: 1 } }, function (error, response) { // ... });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.delete([params, [callback]])
Delete a typed JSON document from a specific index based on its id.
The default method is DELETE
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Delete the document /myindex/mytype/1
.
client.delete({ index: 'myindex', type: 'mytype', id: '1' }, function (error, response) { // ... });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.deleteByQuery([params, [callback]])
Delete documents from one or more indices and one or more types based on a query.
The default method is DELETE
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Deleting documents with a simple query.
client.deleteByQuery({ index: 'myindex', q: 'test' }, function (error, response) { // ... });
Deleting documents using the Query DSL.
client.delete_by_query({ index: 'posts', body: { term: { published: false } } }, function (error, response) { // ... });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.exists([params, [callback]])
Returns a boolean indicating whether or not a given document exists.
The default method is HEAD
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Check that the document /myindex/mytype/1
exits.
client.exists({ index: 'myindex', type: 'mytype', id: 1 }, function (error, exists) { if (exists === true) { // ... } else { // ... } });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.explain([params, [callback]])
Provides details about a specific document’s score in relation to a specific query. It will also tell you if the document matches the specified query. Also check out percolaters.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
See how a document is scored against a simple query.
client.explain({ // the document to test index: 'myindex', type: 'mytype', id: '1', // the query to score it against q: 'field:value' }, function (error, response) { // ... });
See how a document is scored against a query written in the Query DSL.
client.explain({ index: 'myindex', type: 'mytype', id: '1', body: { query: { match: { title: 'test' } } } }, function (error, response) { // ... });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.get([params, [callback]])
Get a typed JSON document from the index based on its id.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Get /myindex/mytype/1
.
client.get({ index: 'myindex', type: 'mytype', id: 1 }, function (error, response) { // ... });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.getSource([params, [callback]])
Get the source of a document by it’s index, type and id.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.index([params, [callback]])
Stores a typed JSON document in an index, making it searchable. When the id
param is not set, a unique id will be auto-generated. When you specify an id
either a new document will be created, or an existing document will be updated. To enforce "put-if-absent" behavior set the opType
to "create"
or use the create()
method.
Optimistic concurrency control is performed, when the version
argument is specified. By default, no version checks are performed.
By default, the document will be available for get()
actions immediately, but will only be available for searching after an index refresh (which can happen automatically or manually). See indices.refresh
.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Create or update a document.
client.index({ index: 'myindex', type: 'mytype', id: '1', body: { title: 'Test 1', tags: ['y', 'z'], published: true, } }, function (error response) { });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.info([params, [callback]])
Get basic info from the current cluster.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
client.mget([params, [callback]])
Get multiple documents based on an index, type (optional) and ids. The body required by mget can take two forms: an array of document locations, or an array of document ids.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
An array of doc locations. Useful for getting documents from different indices.
client.mget({ body: { docs: [ { _index: 'indexA', _type: 'typeA', _id: '1' }, { _index: 'indexB', _type: 'typeB', _id: '1' }, { _index: 'indexC', _type: 'typeC', _id: '1' } ] } }, function(error, response){ // ... });
An array of ids. You must also specify the index
and type
that apply to all of the ids.
client.mget({ index: 'myindex', type: 'mytype', body: { ids: [1, 2, 3] } }, function(error, response){ // ... });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.mlt([params, [callback]])
(more like this) Gets more documents that are “like” the document specified using index
, type
, and id
.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Search for similar documents using the title
property of document myindex/mytype/1
.
client.mlt({ index: 'myindex', type: 'mytype', id: 1, mlt_fields: 'title' }, function (errors, response) { // ... });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.msearch([params, [callback]])
Execute several search requests within the same request.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Perform multiple different searches, the body is made up of meta/data pairs.
client.msearch({ body: [ // match all query, on all indices and types {} { query: { match_all: {} } }, // query_string query, on index/mytype { index: 'myindex', type: 'mytype' }, { query: { query_string: { query: '"Test 1"' } } } ] });
|
|
|
|
|
|
client.percolate([params, [callback]])
Match a document against registered percolator queries.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
First, Register queries named “alert-1” and “alert-2” for the “myindex” index.
client.index({ index: '_percolator', type: 'myindex', id: 'alert-1', body: { // This query will be run against documents sent to percolate query: { query_string: { query: 'foo' } } } }, function (error, response) { // ... }); client.index({ index: '_percolator', type: 'myindex', id: 'alert-2', body: { // This query will also be run against documents sent to percolate query: { query_string: { query: 'bar' } } } }, function (error, response) { // ... });
Then you can send documents to learn which query _percolator
queries they match.
client.percolate({ index: 'myindex', body: { doc: { title: "Foo" } } }, function (error, response) { // response would equal // { // ok:true, // matches: [ "alert-1" ] // } }); client.percolate({ index: 'myindex', body: { doc: { title: "Foo Bar" } } }, function (error, response) { // response would equal // { // ok:true, // matches: [ "alert-1", "alert-2" ] // } });
|
|
|
|
|
|
client.ping([params, [callback]])
The default method is HEAD
and the usual params and return values apply. See the elasticsearch docs for more about this method.
client.scroll([params, [callback]])
Scroll a search request (retrieve the next set of results) after specifying the scroll parameter in a search()
call.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Collect every title in the index that contains the word "test".
var allTitles = []; // first we do a search, and specify a scroll timeout client.search({ index: 'myindex', // Set to 30 seconds because we are calling right back scroll: '30s', fields: ['title'], q: 'title:test' }, function getMoreUntilDone(error, response) { // collect the title from each response response.hits.hists.forEach(function (hit) { allTitles.push(hit.fields.title); }); if (response.hits.total !== allTitles.length) { // now we can call scroll over and over client.scroll({ scrollId: response._scroll_id, scroll: '30s' }, getMoreUntilDone); } else { console.log('every "test" title', allTitles); } });
|
|
|
|
client.search([params, [callback]])
Return documents matching a query, aggregations/facets, highlighted snippets, suggestions, and more. Write your queries as either simple query strings in the q
parameter, or by specifying a full request definition using the Elasticsearch Query DSL in the body
parameter.

elastic.js can be used to make building query bodies easier.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Search with a simple query string query.
client.search({ index: 'myindex', q: 'title:test' }, function (error, response) { // ... });
Passing a full request definition in the Elasticsearch’s Query DSL as a Hash
.
client.search({ index: 'myindex', body: { query: { match: { title: 'test' } }, facets: { tags: { terms: { field: 'tags' } } } } }, function (error, response) { // ... }):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.suggest([params, [callback]])
The suggest feature suggests similar looking terms based on a provided text by using a specific suggester.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Return query terms suggestions (“auto-correction”).
client.suggest({ index: 'myindex', body: { mysuggester: { text: 'tset', term: { field: 'title' } } } }, function (error, response) { // response will be formatted like so: // // { // ... // mysuggester: [ // { // text: "tset", // ... // options: [ // { // text: "test", // score: 0.75, // freq: 5 // } // ] // } // ] // } });
|
|
|
|
|
|
|
|
|
|
client.update([params, [callback]])
Update parts of a document. The required body parameter can contain one of two things:
- a partial document, which will be merged with the existing one.
-
a
script
which will update the document content
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Update document title using partial document.
client.update({ index: 'myindex', type: 'mytype', id: '1', body: { // put the partial document under the `doc` key doc: { title: 'Updated' } } }, function (error, response) { // ... })
Add a tag to document tags
property using a script
.
client.update({ index: 'myindex', type: 'mytype', id: '1', body: { script: 'ctx._source.tags += tag', params: { tag: 'some new tag' } } }, function (error, response) { // ... });
Increment a document counter by 1 or initialize it, when the document does not exist.
client.update({ index: 'myindex', type: 'mytype', id: '666', body: { script: 'ctx._source.counter += 1', upsert: { counter: 1 } } }, function (error, response) { // ... })
Delete a document if it’s tagged “to-delete”.
client.update({ index: 'myindex', type: 'mytype', id: '1', body: { script: 'ctx._source.tags.contains(tag) ? ctx.op = "delete" : ctx.op = "none"', params: { tag: 'to-delete' } } }, function (error, response) { // ... });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.cluster.getSettings([params, [callback]])
Get cluster settings (previously set with putSettings()
)
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
client.cluster.health([params, [callback]])
Get a very simple status on the health of the cluster.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.cluster.nodeHotThreads([params, [callback]])
Returns information about the hottest threads in the cluster or on a specific node as a String. The information is returned as text, and allows you to understand what are currently the most taxing operations happening in the cluster, for debugging or monitoring purposes.

This endpoint returns plain text
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Return 10 hottest threads.
client.cluster.nodeHotThreads({ threads: 10 nodeId: 'mymisbehavingnode', maxRetries: 10 }, function (error, response) { console.log(response); })
|
|
|
|
|
|
|
|
|
|
client.cluster.nodeInfo([params, [callback]])
Retrieve one or more (or all) of the cluster nodes' information.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
Return information about JVM.
client.cluster.nodeInfo({ jvm: true }) .then(function (response) { // enjoy your sweet info! }, function (error) { // scream! })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.cluster.nodeShutdown([params, [callback]])
Shutdown one or more (or all) nodes in the cluster.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.cluster.nodeStats([params, [callback]])
Retrieve one or more (or all) of the cluster nodes statistics.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.cluster.putSettings([params, [callback]])
Update cluster wide specific settings.
The default method is PUT
and the usual params and return values apply. See the elasticsearch docs for more about this method.
client.cluster.reroute([params, [callback]])
Explicitly execute a cluster reroute allocation command including specific commands.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
client.cluster.state([params, [callback]])
Get comprehensive details about the state of the whole cluster (indices settings, allocations, etc).
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.indices.analyze([params, [callback]])
Perform the analysis process on a text and return the tokens breakdown of the text.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.indices.clearCache([params, [callback]])
Clear either all caches or specific cached associated with one ore more indices.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.indices.close([params, [callback]])
Close an index to remove it’s overhead from the cluster. Closed index is blocked for read/write operations.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.create([params, [callback]])
Create an index in Elasticsearch.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.delete([params, [callback]])
Delete an index in Elasticsearch
The default method is DELETE
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.deleteAlias([params, [callback]])
Delete a specific alias.
The default method is DELETE
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
client.indices.deleteMapping([params, [callback]])
Delete a mapping (type definition) along with its data.
The default method is DELETE
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.deleteTemplate([params, [callback]])
Delete an index template by its name.
The default method is DELETE
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.deleteWarmer([params, [callback]])
Delete an index warmer.
The default method is DELETE
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
client.indices.exists([params, [callback]])
Return a boolean indicating whether given index exists.
The default method is HEAD
and the usual params and return values apply. See the elasticsearch docs for more about this method.
client.indices.existsAlias([params, [callback]])
Return a boolean indicating whether given alias exists.
The default method is HEAD
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.existsType([params, [callback]])
Check if a type/types exists in an index/indices.
The default method is HEAD
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.flush([params, [callback]])
Explicitly flush one or more indices.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
client.indices.getAlias([params, [callback]])
Retrieve a specified alias.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.getAliases([params, [callback]])
Retrieve specified aliases
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
client.indices.getFieldMapping([params, [callback]])
Retrieve mapping definition of a specific field.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
client.indices.getMapping([params, [callback]])
Retrieve mapping definition of index or index/type.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
client.indices.getSettings([params, [callback]])
Retrieve settings for one or more (or all) indices.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
client.indices.getTemplate([params, [callback]])
Retrieve an index template by its name.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
client.indices.getWarmer([params, [callback]])
Retreieve an index warmer.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.open([params, [callback]])
Open a closed index, making it available for search.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.optimize([params, [callback]])
Explicitly optimize one or more indices.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.indices.putAlias([params, [callback]])
Create an alias for a specific index/indices.
The default method is PUT
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
client.indices.putMapping([params, [callback]])
Register specific mapping definition for a specific type.
The default method is PUT
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
client.indices.putSettings([params, [callback]])
Change specific index level settings in real time.
The default method is PUT
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
client.indices.putTemplate([params, [callback]])
Create an index template that will automatically be applied to new indices created.
The default method is PUT
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
client.indices.putWarmer([params, [callback]])
Create an index warmer to run registered search requests to warm up the index before it is available for search.
The default method is PUT
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
client.indices.refresh([params, [callback]])
Explicitly refresh one or more index, making all operations performed since the last refresh available for search.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.segments([params, [callback]])
Retrieve low level segments information that a Lucene index (shard level) is built with.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.snapshotIndex([params, [callback]])
Initiate a snapshot through the gateway of one or more indices.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
client.indices.stats([params, [callback]])
Retrieve statistics on different operations happening on an index.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
client.indices.status([params, [callback]])
Get a comprehensive status information of one or more indices.
The default method is GET
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
client.indices.updateAliases([params, [callback]])
Update specified aliases.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
client.indices.validateQuery([params, [callback]])
Validate a potentially expensive query without executing it.
The default method is POST
and the usual params and return values apply. See the elasticsearch docs for more about this method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|