Index Class
Provides methods for creating, deleting, and interacting with ElasticSearch indices.
Item Index
Methods
- addAlias static
- analyze
- analyze static
- bulk static
- count static
- create static
- delete
- delete static
- deleteIndex
- deleteRiver static
- deleteRiver static
- exists
- exists static
- get
- getAliases static
- getMapping static
- getMapping
- getRiver static
- getRiver static
- getSettings static
- index
- multiGet
- putMapping static
- putMapping
- putRiver static
- putRiver static
- refresh static
- refresh
- search
- set
- setPercolator
- stats
- updateSettings static
Methods
addAlias
-
client
-
actions
-
callback
Apply aliases actions.
Parameters:
-
client
ClientClient instance.
-
actions
ObjectAliases actions.
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
analyze
-
text
-
[options]
-
[callback]
Analyze using analyzer from this index
Parameters:
-
text
StringText to analyze
-
[options]
Object optionalOptions. See ElasticSearch docs for details.
-
[analyzer="standard"]
String optionalAnalyzer to use for analysis
-
[tokenizer="keyword"]
String optionalTokenizer to use for analysis when using a custom transient analyzer
-
[field="obj1.field1"]
String optionalUse the analyzer configured in the mapping for this field
-
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
analyze
-
client
-
text
-
[options]
-
[callback]
Analyze
Parameters:
-
client
ClientClient instance.
-
text
StringText to analyze
-
[options]
Object optionalOptions. See ElasticSearch docs for details.
-
[index="indexname"]
String optionalIndex name whose analyzer must be used. If not specified, use built-in analyzers.
-
[analyzer="standard"]
String optionalAnalyzer to use for analysis
-
[tokenizer="keyword"]
String optionalTokenizer to use for analysis when using a custom transient analyzer
-
[field="obj1.field1"]
String optionalUse the analyzer configured in the mapping for this field
-
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
bulk
-
client
-
operations
-
[options]
-
[callback]
Performs multiple document create/index/delete operations in a single request.
The operations parameter should be an array of objects. Each object must adhere to one of the following formats.
Operation Objects
Create a Document
{
create: {
index: 'index-name',
type : 'type-name',
id : 'document-id',
data : { ... document data ... },
// Optional properties.
parent : '...',
percolate : '...',
routing : '...',
version : '...',
version_type: 'internal' | 'external'
}
}
Index a Document
{
index: {
index: 'index-name',
type : 'type-name',
id : 'document-id',
data : { ... document data ... },
// Optional properties.
parent : '...',
percolate : '...',
routing : '...',
version : '...',
version_type: 'internal' | 'external'
}
}
Delete a Document
{
delete: {
index: 'index-name',
type : 'type-name',
id : 'document-id',
// Optional properties.
parent : '...',
routing: '...',
version: '...'
}
}
Parameters:
-
client
ClientClient instance.
-
operations
ObjectArray of operations to perform. See above for a description of the expected object format.
-
[options]
Object optionalOptions.
-
[consistency="quorum"]
String optionalWrite consistency to use for these operations. Permitted values are "one", "quorum", and "all". See the ElasticSearch docs for details.
-
[refresh=false]
Boolean optionalIf
true
, the relevant shard will be refreshed after the delete operation. This may cause heavy server load, so use with caution. -
[index="indexname"]
String optionalIf specified the url endpoint for the bulk operations will include this index. This is useful for scenarios where the root -bulk endpoint is prevented on a shared cluster.
-
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
Example:
index.bulk(client, [
{create: {index: 'blog', type: 'post', id: '1', data: {
title: 'Hello',
body : 'Welcome to my stupid blog.'
}}},
{index: {index: 'blog', type: 'post', id: '2', data: {
title: 'Breaking news',
body : 'Today I ate a sandwich.'
}}},
{index: {index: 'blog', type: 'post', id: '3', percolate: '*', data: {
title: 'Percolate this',
body : 'Run against all percolators.'
}}},
{delete: {index: 'blog', type: 'post', id: '42'}}
], function (err, res) {
// ...
});
count
-
client
-
names
-
[type]
-
query
-
callback
Retrieve the mappings for one or more indices.
Parameters:
-
client
ClientClient instance.
-
names
String | StringIndex name or array of names.
-
[type]
String optionalDocument type. If omitted, count for all types are returned.
-
query
Stringquery. If omitted, count for a match_all is returned.
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
create
-
client
-
name
-
[options]
-
[callback]
Creates a new index.
Parameters:
-
client
ClientClient instance.
-
name
StringName of the new index.
-
[options]
Object optionalIndex options (see ElasticSearch docs for details).
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
index
IndexIndex instance for the newly created index.
-
data
ObjectElasticSearch response data.
-
delete
-
type
-
id
-
[options]
-
[callback]
Deletes a document from this index.
Parameters:
-
type
StringType name.
-
id
StringDocument id to delete.
-
[options]
Object optionalDelete options.
-
[consistency="quorum"]
String optionalWrite consistency to use for this indexing operation. Permitted values are "one", "quorum" and "all". See the ElasticSearch docs for details.
-
[ignoreMissing=false]
Boolean optionalIf
true
, an error will not be returned if the index, type, or document do not exist. -
[parent]
String optionalParent document id.
-
[refresh=false]
Boolean optionalIf
true
, the relevant shard will be refreshed after the delete operation. This may cause heavy server load, so use with caution. -
[replication="sync"]
String optionalReplication mode for this indexing operation. Maybe be set to "sync" or "async".
-
[routing]
String optionalValue that determines what shard this operation will be routed to. Note that an incorrectly routed operation will fail, so it's best to leave this alone unless you know your business.
-
[version]
Number optionalDocument version to delete. If the specified document's version differs from this, an error will be returned and the document will not be deleted.
-
[query]
Object optionalTo perform removal using a query. Warning: id and all other options except ignoreMissing will be ignored.
-
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response.
-
delete
-
client
-
[names]
-
[callback]
Deletes the specified index or indices. If no indices are specified, all indices on the server will be deleted.
Parameters:
-
client
ClientClient instance.
-
[names]
String | String optionalName of the index to delete, or an array of names to delete multiple indices. If omitted, all indices will be deleted.
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
data
ObjectElasticSearch response data.
-
deleteIndex
-
[callback]
Deletes this index.
Parameters:
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
data
ObjectElasticSearch response data.
-
deleteRiver
-
client
-
name
-
[callback]
Deletes a river config from the cluster.
Parameters:
-
client
ClientClient instance.
-
name
StringA name for this river.
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
deleteRiver
-
client
-
name
-
[callback]
Deletes a river config from the cluster.
Parameters:
-
client
ClientClient instance.
-
name
StringA name for this river.
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
exists
-
callback
Checks whether this index exists on the server.
Parameters:
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
exists
Booleantrue
if the index exists,false
otherwise.
-
exists
-
client
-
names
-
callback
Checks whether the specified index or indices exist.
Parameters:
-
client
ClientClient instance.
-
names
String | StringIndex name or array of names to check.
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
exists
Booleantrue
if all specified indices exist,false
otherwise.
-
get
-
id
-
[options]
-
callback
Gets a document from this index based on its id.
Parameters:
-
id
StringDocument id.
-
[options]
Object optionalOptions.
-
[fields]
String | String optionalDocument field name or array of field names to retrieve. By default, all fields are retrieved.
-
[ignoreMissing=false]
Boolean optionalIf
true
, an error will not be returned if the index, type, or document do not exist. Instead, anull
document will be returned. -
[preference]
String optionalControls which shard replicas the request should be executed on. By default, the operation will be randomized between the shard replicas. See the ElasticSearch docs for possible values.
-
[realtime=true]
Boolean optionalWhether or not to use realtime GET. See the ElasticSearch docs for details.
-
[refresh=false]
Boolean optionalIf
true
, the relevant shard will be refreshed before the get operation to ensure that it's searchable. This may cause heavy server load, so use with caution. -
[routing]
String optionalValue that determines what shard this document will be routed to. If not specified, a hash of the document's id will be used. Note that an incorrectly routed get operation will fail, so it's best to leave this alone unless you know your business.
-
[type="_all"]
String optionalIf specified, the get operation will be limited to documents of this type.
-
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
doc
Object | NullRetrieved document or document fields, or
null
if the document was not found andoptions.ignoreMissing
istrue
. -
res
ObjectFull ElasticSearch response data.
-
getAliases
-
client
-
names
-
callback
Get aliases.
Parameters:
-
client
ClientClient instance.
-
names
String | String | NullIndex name or array of names.
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
getMapping
-
client
-
names
-
[type]
-
callback
Retrieve the mappings for one or more indices.
Parameters:
-
client
ClientClient instance.
-
names
String | StringIndex name or array of names.
-
[type]
String optionalDocument type. If omitted, mappings for all types are returned.
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
getMapping
-
[type]
-
callback
Gets the mapping definition for this index.
Parameters:
-
[type]
String optionalDocument type. If omitted, mappings for all types are returned.
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
getRiver
-
client
-
name
-
[callback]
Gets river config from the cluster.
Parameters:
-
client
ClientClient instance.
-
name
StringA name for this river.
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
getRiver
-
client
-
name
-
[callback]
Gets river config from the cluster. ElasticSearch docs
Parameters:
-
client
ClientClient instance.
-
name
StringA name for this river.
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
getSettings
-
client
-
names
-
callback
Retrieve the settings for one or more indices.
Parameters:
-
client
ClientClient instance.
-
names
String | StringIndex name or array of names.
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
index
-
type
-
doc
-
[options]
-
[callback]
Adds a document to this index.
If a document already exists in this index with the specified type and id, it will be updated. Otherwise, a new document will be created.
Parameters:
-
type
StringDocument type.
-
doc
ObjectDocument data to index.
-
[options]
Object optionalOptions.
-
[consistency="quorum"]
String optionalWrite consistency to use for this indexing operation. Permitted values are "one", "quorum" and "all". See the ElasticSearch docs for details.
-
[create=false]
Boolean optionalOnly create the document if it doesn't already exist.
-
[id]
String optionalDocument id. One will be automatically generated if not specified.
-
[parent]
String optionalParent document id.
-
[percolate]
String optionalPercolation query to check against this document. See the ElasticSearch docs for details.
-
[refresh=false]
Boolean optionalIf
true
, the document will be made searchable immediately after it is indexed. -
[replication="sync"]
String optionalReplication mode for this indexing operation. Maybe be set to "sync" or "async".
-
[routing]
String optionalValue that determines what shard this document will be routed to. If not specified, a hash of the document's id will be used.
-
[timeout="1m"]
String optionalHow long to wait for the primary shard to become available to index this document before aborting. See the ElasticSearch docs for details. This should be a value like "5m" (5 minutes) or "15s" (15 seconds).
-
[version]
Number optionalDocument version to create/update. If this is set and
options.version_type
is not set,options.version_type
will automatically be set to "external". -
[version_type="internal"]
String optionalVersion type (either "internal" or "external"). See the ElasticSearch docs for details.
-
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
Example:
var blog = client.getIndex('blog');
blog.index('post', {
title : "Welcome to my stupid blog",
content: "This is the first and last time I'll post anything.",
tags : ['welcome', 'first post', 'last post'],
created: Date.now()
}, function (err, res) {
if (err) { throw err; }
console.log('Indexed a blog post');
});
multiGet
-
client
-
index
-
type
-
data
-
callback
Multi GET API allows to get multiple documents
Parameters:
-
client
ClientClient instance.
-
index
String | Nulloptional Index name.
-
type
String | Nulloptional document type.
-
data
Objecteither docs or ids
-
[docs]
Object optionaldocs to query (can include _index, _type, _id, fields)
-
[ids]
String optionalids to query
-
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
putMapping
-
client
-
[names]
-
type
-
[mapping]
-
[callback]
Registers a mapping definition for the specified type within the specified index or indices.
Parameters:
-
client
ClientClient instance.
-
[names]
String | String optionalIndex name or array of names to define the mapping within. If not specified, it will be defined in all indices.
-
type
StringDocument type.
-
[mapping]
Object optionalMapping definition. See the ElasticSearch docs for an overview.
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
putMapping
-
type
-
[mapping]
-
[callback]
Registers a mapping definition for the specified type within this index.
Parameters:
-
type
StringDocument type.
-
[mapping]
Object optionalMapping definition. See the ElasticSearch docs for an overview.
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
putRiver
-
client
-
name
-
config
-
[callback]
Registers a river with the cluster.
Parameters:
-
client
ClientClient instance.
-
name
StringA name for this river.
-
config
ObjectThe river configuration.
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
putRiver
-
name
-
config
-
[callback]
Registers a river with the cluster. ElasticSearch docs
Parameters:
-
name
StringA name for this river.
-
config
ObjectThe river configuration.
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
refresh
-
client
-
[names]
-
[callback]
Refreshes the specified index or indices.
Parameters:
-
client
ClientClient instance.
-
[names]
String | String optionalIndex name or array of names to refresh. If not specified, all indices will be refreshed.
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
refresh
-
[callback]
Refreshes this index.
Parameters:
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
search
-
[options]
-
callback
Searches for documents in this index matching the given query. See
Client.search()
for the complete list of supported options.
Parameters:
-
[options]
Object optionalSearch options. Technically this argument is optional, but you'll almost always want to provide at least a query.
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
results
ObjectSearch results.
-
res
ObjectFull ElasticSearch response data.
-
set
()
Alias for index().
setPercolator
-
percolator
-
query
-
callback
Registers a percolator for the given index or modifies the existing percolator if one with the name already exists
Parameters:
-
percolator
StringThe identifier string of the percolator. This identifier is returned when a document matches the query in the percolator, either through percolate operation or through index opertation.
-
query
Object | StringSearch query. Afull query object. See the ElasticSearch Query DSL docs for details.
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectFull ElasticSearch response data.
-
Example:
var put = {
"query" : {
"text" : {
"hashtags" : {
"query" : 'blah blah blah ',
"operator" : "or"
}
}
}
};
client.percolator('tweets', 'mypercolator', query, function (err, res) {
if (err) { throw err; }
console.log(results);
});
stats
-
[options]
-
[callback]
Provide statistics on different operations happening on an index.
See Client.stats()
for the complete list of supported options.
Parameters:
-
[options]
Object optionalStats options. This argument is optional.
-
[callback]
Function optionalCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-
updateSettings
-
client
-
index
-
settings
-
callback
Update the settings for one or more indices.
Parameters:
-
client
ClientClient instance.
-
index
String | StringIndex name or array of names. If not specified, it will be applied to all indices
-
settings
ObjectSettings. See ElasticSearch docs for details.
-
callback
FunctionCallback function.
-
err
Error | NullError, or
null
on success. -
res
ObjectElasticSearch response data.
-