How to fix "Document mapping type name can't start with '_', found: [_create]_" elasticsearch?

7/10/2019

I am using Nodejs to index some data into Elasticsearch(hosted on kubernetes),I am using client.create() method to index document in Elasticsearch. If I run the code on localhost and kubernetes Elasticsearch endpoint, Everything is working fine. But after deploying the same code when I tried indexing a document, I am getting an error:

"[invalid_type_name_exception] Document mapping type name can't start with '_', found: [_create] :: {"path":"/index_name/_create/docId"]".

Elasticsearch version "6.3.0" and node_module version "^16.0.0". Also, it was working initially but stopped working from past few days. I think the issue is with some compatibility and configurations, can anyone please help?

I tried using client.index instead of client.create and it works fine. i already matched all configuration and compatibility files on local and server. Everything seems OK to me.

const elasticsearchDoc = {
      index: "school",
      type: "_doc",
      id: 12345,
      body: { name:"raj",marks:40 }
};
const result = await client.create(elasticsearchDoc);
...
-- Raghu Chahar
elasticsearch
kubernetes
node.js

1 Answer

7/10/2019

I think the problem is that you're using the old JS client library instead of the new one.

With 16.0.0 you need to explicitely set the apiVersion parameter to the 6.x version because 7.0 is the default and that's probably why you're seeing this error (since you're using ES 6.3.0):

apiVersion: 6.7
-- Val
Source: StackOverflow