index

edit
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.

Check the API Conventions and the elasticsearch docs for more information pertaining to this method.

Create or update a document.

const response = await client.index({
  index: 'myindex',
  type: 'mytype',
  id: '1',
  body: {
    title: 'Test 1',
    tags: ['y', 'z'],
    published: true,
  }
});

Params

waitForActiveShards

String — Sets the number of shard copies that must be active before proceeding with the index operation. Defaults to 1, meaning the primary shard only. Set to all for all shard copies, otherwise set to any non-negative value less than or equal to the total number of copies for the shard (number of replicas + 1)

[opType=index]

String — Explicit operation type

Options
  • "index"
  • "create"

parent

String — ID of the parent document

refresh

String — If true then refresh the affected shards to make this operation visible to search, if wait_for then wait for a refresh to make this operation visible to search, if false (the default) then do nothing with refreshes.

Options
  • "true"
  • "false"
  • "wait_for"
  • ""

routing

String — Specific routing value

timeout

DurationString — Explicit operation timeout

timestamp

Timestamp — Explicit timestamp for the document

ttl

DurationString — Expiration time for the document

version

Number — Explicit version number for concurrency control

versionType

String — Specific version type

Options
  • "internal"
  • "external"
  • "external_gte"
  • "force"

pipeline

String — The pipeline id to preprocess incoming documents with

id

String — Document ID

index

String — The name of the index

type

String — The type of the document

body

Object, JSON — The request body, as either JSON or a JSON serializable object. See the elasticsearch docs for details about what can be specified here.

back to top