API Docs for:
Show:

Index Class

Defined in: lib/index.js:1
Module: index
Parent Module: elastical

Provides methods for creating, deleting, and interacting with ElasticSearch indices.

Item Index

Methods

Methods

addAlias

(
  • client
  • actions
  • callback
)
static

Defined in lib/index.js:445

Apply aliases actions.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • actions Object

    Aliases actions.

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

analyze

(
  • text
  • [options]
  • [callback]
)

Defined in lib/index.js:1075

Analyze using analyzer from this index

ElasticSearch docs

Parameters:

  • text String

    Text to analyze

  • [options] Object optional

    Options. See ElasticSearch docs for details.

    • [analyzer="standard"] String optional

      Analyzer to use for analysis

    • [tokenizer="keyword"] String optional

      Tokenizer to use for analysis when using a custom transient analyzer

    • [field="obj1.field1"] String optional

      Use the analyzer configured in the mapping for this field

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

analyze

(
  • client
  • text
  • [options]
  • [callback]
)
static

Defined in lib/index.js:568

Parameters:

  • client Client

    Client instance.

  • text String

    Text to analyze

  • [options] Object optional

    Options. See ElasticSearch docs for details.

    • [index="indexname"] String optional

      Index name whose analyzer must be used. If not specified, use built-in analyzers.

    • [analyzer="standard"] String optional

      Analyzer to use for analysis

    • [tokenizer="keyword"] String optional

      Tokenizer to use for analysis when using a custom transient analyzer

    • [field="obj1.field1"] String optional

      Use the analyzer configured in the mapping for this field

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

bulk

(
  • client
  • operations
  • [options]
  • [callback]
)
static

Defined in lib/index.js:21

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: '...'
    }
}

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • operations Object

    Array of operations to perform. See above for a description of the expected object format.

  • [options] Object optional

    Options.

    • [consistency="quorum"] String optional

      Write consistency to use for these operations. Permitted values are "one", "quorum", and "all". See the ElasticSearch docs for details.

    • [refresh=false] Boolean optional

      If true, the relevant shard will be refreshed after the delete operation. This may cause heavy server load, so use with caution.

    • [index="indexname"] String optional

      If 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 optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch 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
)
static

Defined in lib/index.js:281

Retrieve the mappings for one or more indices.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • names String | String

    Index name or array of names.

  • [type] String optional

    Document type. If omitted, count for all types are returned.

  • query String

    query. If omitted, count for a match_all is returned.

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

create

(
  • client
  • name
  • [options]
  • [callback]
)
static

Defined in lib/index.js:195

Creates a new index.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • name String

    Name of the new index.

  • [options] Object optional

    Index options (see ElasticSearch docs for details).

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • index Index

      Index instance for the newly created index.

    • data Object

      ElasticSearch response data.

delete

(
  • type
  • id
  • [options]
  • [callback]
)

Defined in lib/index.js:708

Deletes a document from this index.

Parameters:

  • type String

    Type name.

  • id String

    Document id to delete.

  • [options] Object optional

    Delete options.

    • [consistency="quorum"] String optional

      Write consistency to use for this indexing operation. Permitted values are "one", "quorum" and "all". See the ElasticSearch docs for details.

    • [ignoreMissing=false] Boolean optional

      If true, an error will not be returned if the index, type, or document do not exist.

    • [parent] String optional

      Parent document id.

    • [refresh=false] Boolean optional

      If true, the relevant shard will be refreshed after the delete operation. This may cause heavy server load, so use with caution.

    • [replication="sync"] String optional

      Replication mode for this indexing operation. Maybe be set to "sync" or "async".

    • [routing] String optional

      Value 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 optional

      Document 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 optional

      To perform removal using a query. Warning: id and all other options except ignoreMissing will be ignored.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response.

delete

(
  • client
  • [names]
  • [callback]
)
static

Defined in lib/index.js:226

Deletes the specified index or indices. If no indices are specified, all indices on the server will be deleted.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • [names] String | String optional

    Name of the index to delete, or an array of names to delete multiple indices. If omitted, all indices will be deleted.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • data Object

      ElasticSearch response data.

deleteIndex

(
  • [callback]
)

Defined in lib/index.js:803

Deletes this index.

ElasticSearch docs

Parameters:

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • data Object

      ElasticSearch response data.

deleteRiver

(
  • client
  • name
  • [callback]
)
static

Defined in lib/index.js:655

Deletes a river config from the cluster.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • name String

    A name for this river.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

deleteRiver

(
  • client
  • name
  • [callback]
)
static

Defined in lib/index.js:1134

Deletes a river config from the cluster.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • name String

    A name for this river.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

exists

(
  • callback
)

Defined in lib/index.js:822

Checks whether this index exists on the server.

ElasticSearch docs

Parameters:

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • exists Boolean

      true if the index exists, false otherwise.

exists

(
  • client
  • names
  • callback
)
static

Defined in lib/index.js:256

Checks whether the specified index or indices exist.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • names String | String

    Index name or array of names to check.

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • exists Boolean

      true if all specified indices exist, false otherwise.

get

(
  • id
  • [options]
  • callback
)

Defined in lib/index.js:837

Gets a document from this index based on its id.

ElasticSearch docs

Parameters:

  • id String

    Document id.

  • [options] Object optional

    Options.

    • [fields] String | String optional

      Document field name or array of field names to retrieve. By default, all fields are retrieved.

    • [ignoreMissing=false] Boolean optional

      If true, an error will not be returned if the index, type, or document do not exist. Instead, a null document will be returned.

    • [preference] String optional

      Controls 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 optional

      Whether or not to use realtime GET. See the ElasticSearch docs for details.

    • [refresh=false] Boolean optional

      If 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 optional

      Value 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 optional

      If specified, the get operation will be limited to documents of this type.

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • doc Object | Null

      Retrieved document or document fields, or null if the document was not found and options.ignoreMissing is true.

    • res Object

      Full ElasticSearch response data.

getAliases

(
  • client
  • names
  • callback
)
static

Defined in lib/index.js:466

Get aliases.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • names String | String | Null

    Index name or array of names.

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

getMapping

(
  • client
  • names
  • [type]
  • callback
)
static

Defined in lib/index.js:333

Retrieve the mappings for one or more indices.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • names String | String

    Index name or array of names.

  • [type] String optional

    Document type. If omitted, mappings for all types are returned.

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

getMapping

(
  • [type]
  • callback
)

Defined in lib/index.js:928

Gets the mapping definition for this index.

ElasticSearch docs

Parameters:

  • [type] String optional

    Document type. If omitted, mappings for all types are returned.

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

getRiver

(
  • client
  • name
  • [callback]
)
static

Defined in lib/index.js:638

Gets river config from the cluster.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • name String

    A name for this river.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

getRiver

(
  • client
  • name
  • [callback]
)
static

Defined in lib/index.js:1118

Gets river config from the cluster. ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • name String

    A name for this river.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

getSettings

(
  • client
  • names
  • callback
)
static

Defined in lib/index.js:372

Retrieve the settings for one or more indices.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • names String | String

    Index name or array of names.

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

index

(
  • type
  • doc
  • [options]
  • [callback]
)

Defined in lib/index.js:945

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.

ElasticSearch docs

Parameters:

  • type String

    Document type.

  • doc Object

    Document data to index.

  • [options] Object optional

    Options.

    • [consistency="quorum"] String optional

      Write consistency to use for this indexing operation. Permitted values are "one", "quorum" and "all". See the ElasticSearch docs for details.

    • [create=false] Boolean optional

      Only create the document if it doesn't already exist.

    • [id] String optional

      Document id. One will be automatically generated if not specified.

    • [parent] String optional

      Parent document id.

    • [percolate] String optional

      Percolation query to check against this document. See the ElasticSearch docs for details.

    • [refresh=false] Boolean optional

      If true, the document will be made searchable immediately after it is indexed.

    • [replication="sync"] String optional

      Replication mode for this indexing operation. Maybe be set to "sync" or "async".

    • [routing] String optional

      Value 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 optional

      How 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 optional

      Document 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 optional

      Version type (either "internal" or "external"). See the ElasticSearch docs for details.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch 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
)

Defined in lib/index.js:672

Multi GET API allows to get multiple documents

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • index String | Null

    optional Index name.

  • type String | Null

    optional document type.

  • data Object

    either docs or ids

    • [docs] Object optional

      docs to query (can include _index, _type, _id, fields)

    • [ids] String optional

      ids to query

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

putMapping

(
  • client
  • [names]
  • type
  • [mapping]
  • [callback]
)
static

Defined in lib/index.js:497

Registers a mapping definition for the specified type within the specified index or indices.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • [names] String | String optional

    Index name or array of names to define the mapping within. If not specified, it will be defined in all indices.

  • type String

    Document type.

  • [mapping] Object optional

    Mapping definition. See the ElasticSearch docs for an overview.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

putMapping

(
  • type
  • [mapping]
  • [callback]
)

Defined in lib/index.js:1056

Registers a mapping definition for the specified type within this index.

ElasticSearch docs

Parameters:

  • type String

    Document type.

  • [mapping] Object optional

    Mapping definition. See the ElasticSearch docs for an overview.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

putRiver

(
  • client
  • name
  • config
  • [callback]
)
static

Defined in lib/index.js:617

Registers a river with the cluster.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • name String

    A name for this river.

  • config Object

    The river configuration.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

putRiver

(
  • name
  • config
  • [callback]
)
static

Defined in lib/index.js:1102

Registers a river with the cluster. ElasticSearch docs

Parameters:

  • name String

    A name for this river.

  • config Object

    The river configuration.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

refresh

(
  • client
  • [names]
  • [callback]
)
static

Defined in lib/index.js:537

Refreshes the specified index or indices.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • [names] String | String optional

    Index name or array of names to refresh. If not specified, all indices will be refreshed.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

refresh

(
  • [callback]
)

Defined in lib/index.js:1151

Refreshes this index.

ElasticSearch docs

Parameters:

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

set

()

Defined in lib/index.js:1340

Alias for index().

setPercolator

(
  • percolator
  • query
  • callback
)

Defined in lib/index.js:1213

Registers a percolator for the given index or modifies the existing percolator if one with the name already exists

ElasticSearch docs

Parameters:

  • percolator String

    The 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 | String

    Search query. Afull query object. See the ElasticSearch Query DSL docs for details.

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      Full 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]
)

Defined in lib/index.js:1190

Provide statistics on different operations happening on an index. See Client.stats() for the complete list of supported options.

ElasticSearch docs

Parameters:

  • [options] Object optional

    Stats options. This argument is optional.

  • [callback] Function optional

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.

updateSettings

(
  • client
  • index
  • settings
  • callback
)
static

Defined in lib/index.js:401

Update the settings for one or more indices.

ElasticSearch docs

Parameters:

  • client Client

    Client instance.

  • index String | String

    Index name or array of names. If not specified, it will be applied to all indices

  • settings Object

    Settings. See ElasticSearch docs for details.

  • callback Function

    Callback function.

    • err Error | Null

      Error, or null on success.

    • res Object

      ElasticSearch response data.