Method: Elasticsearch::Model::Indexing::InstanceMethods#index_document

Defined in:
lib/elasticsearch/model/indexing.rb

#index_document(options = {}) ⇒ Hash

Serializes the model instance into JSON (by calling ‘as_indexed_json`), and saves the document into the Elasticsearch index.

Examples:

Index a record


@article.__elasticsearch__.index_document
2013-11-20 16:25:57 +0100: PUT http://localhost:9200/articles/article/1 ...

Parameters:

  • options (Hash) (defaults to: {})

    Optional arguments for passing to the client

Returns:

  • (Hash)

    The response from Elasticsearch

See Also:

[View source]

361
362
363
364
365
366
367
368
# File 'lib/elasticsearch/model/indexing.rb', line 361

def index_document(options={})
  document = as_indexed_json
  request = { index: index_name,
              id:    id,
              body:  document }

  client.index(request.merge!(options))
end