ES 5.0 - op_type=create ERROR


#1

Hello everybody,

First of all my setup:

  • ES 5 (upgraded from 2.4)
  • My node.js app is accessing ES using the JavaScript API
  • documents IDs are autogenerated by elastic

When running ES 2.4 issuing a create call such as:

client.create({
  index: 'myindex',
  type: 'mytype',
  body: {
    title: 'Test 1',
    tags: ['y', 'z'],
    published: true,
    published_at: '2013-01-01',
    counter: 1
  }
}, function (error, response) {
  // ...
});

would result, as expected, in the creation of a document.

Now, with ES 5.0, the same call results in this error:

{ "error": { "root_cause": [
    { 
      "type":"action_request_validation_exception",
      "reason":"Validation Failed: 1: an id must be provided if version type or value are set;"
    }
  ],
  "type":"action_request_validation_exception",
  "reason":"Validation Failed: 1: an id must be provided if version type or value are set;"},
  "status":400
}

The javascript call gets 'translated' into this REST call:

POST localhost:9200/examples/example?op_type=create
{
  index: 'myindex',
  type: 'mytype',
  body: {
    title: 'Test 1',
    tags: ['y', 'z'],
    published: true,
    published_at: '2013-01-01',
    counter: 1
  }
}

If I remove the op_type=create then everything is fine (note that in ES 2.4 the exact same REST call would result in the document being indexed, no problems)

I did not find anything in breaking changes mentioning something about the create API, but maybe I did not look hard enough into it.

Has anyone ran into this problem or can give me a hint or two how to solve this?

Thanks


(Shane Connelly) #2

You have to specify id in 5.0 when using op_type=create. You can find the breaking changes doc for this at https://www.elastic.co/guide/en/elasticsearch/reference/5.0/breaking_50_index_apis.html#_optype_create_without_an_id


#3

Thank you @shanec, but I was trying to understand why the javascript library stopped working and probably I wasn't clear enough.

I do not directly set op_type=create, the library does it and obviously, now, I need to specify an ID while before I did not.

Fortunately, I can use index instead of create. Then, the ID is autogenerated as before.


(system) #4