Skip to content

Latest commit

 

History

History
74 lines (59 loc) · 2.01 KB

File metadata and controls

74 lines (59 loc) · 2.01 KB

Class CreateCommand

The CreateCommand class is used for creating documents.

CommandIndexCommandTypeCommandDocumentCommandStoreCommand ← CreateCommand

REST API:

PUT /<index>/<type>/<id>/_create

Methods

  • constructor(index, type, id, source, params) - Initializes new instance of command.
  • execute(client) - Executes this command.

Methods inherited from StoreCommand

  • getSource() - Returns source of document.
  • setSource(source) - Sets source of document.

Methods inherited from DocumentCommand

  • getId() - Returns identifier of document.
  • setId(id) - Sets identifier of document.

Methods inherited from TypeCommand

  • getType() - Returns name of type.
  • setType(type) - Sets name of type.

Methods inherited from IndexCommand

  • getIndex() - Returns name of index.
  • setIndex(index) - Sets name of index.

Methods inherited from Command

  • getParameter(name) - Returns value of the specified parameter.
  • setParameter(name, value) - Sets value of the specified parameter.

Usage

var elastic = require("elastic");
var client = new elastic.Client({/*options*/});

var post = {
    "title": "My first post",
    "tags": ["first post", "store command"],
    "message": "This is my first post.",
    "user": "Me"
};

var cmd = new elastic.CreateCommand("test", "post", "1", post);
cmd.execute(client).then(function (result) {
    console.log(JSON.stringify(result, null, "    "));
});

Result

{
    "_index": "test",
    "_type": "post",
    "_id": "1",
    "_version": 1,
    "created": true
}

Method constructor(index, type, id, source, params)

constructor([index: string, [type: string, [id: string, [source: object, [params: object]]]]])

Method execute(client)

execute(client: Client): Promise