Node - Bulk indexing not working - Content-Type header [application/x-ldjson] is not supported


(Venkatesan) #1

Am new and exploring elasticsearch integration with node and trying to execute the following example in my windows.

while trying to import the data from data.json, the 'node index.js' is able to only parse the items in data file but not indexing those items into my elasticsearch instance.

I am not getting the log statement "Successfully indexed 1000 out of 1000 items" printed.

esClient.bulk({body: bulkBody})
.then(response => {
let errorCount = 0;
response.items.forEach(item => {
if (item.index && item.index.error) {
console.log(++errorCount, item.index.error);
}
});
console.log(Successfully indexed ${data.length - errorCount} out of ${data.length} items);
})
.catch(console.err);
};

Any idea what step is missing here?

java version 1.8.0_121
elasticsearch version 6.1.1
node version v8.5.0

--
Thanks.
Venkkiram


(Venkatesan) #2

By enabling the trace, I now see the following as the root cause.

"error": "Content-Type header [application/x-ldjson] is not supported",
** "status": 406**

This happens in bulk indexing while index.js parsing the items from data.json file and trying to index as a bulk.

I see a change log from elasticsearch says following

13.0.0 (Apr 24 2017)
bulk and other APIs that send line-delimited JSON bodies now use the Content-Type: application/x-ndjson header #507

Any idea how to resolve this content type issue in index.js?

Thanks.


(David Pilato) #3

13.0.0 (Apr 24 2017)

Where did you find that please?


(Venkatesan) #4

the following link describes the changelog content I shared,

https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/changelog.html

13.0.0 (Apr 24 2017)
bulk and other APIs that send line-delimited JSON bodies now use the Content-Type: application/x-ndjson header #507


(David Pilato) #5

Thanks. As I wrote in

I think this should be reported in https://github.com/elastic/elasticsearch-js instead. But make sure first that you are upgrading to the latest version of the JS client.


(Venkatesan) #6

Have upgraded npm and node in local windows. Still same error behaviour as below.

<- 406
{
"error": "Content-Type header [application/x-ldjson] is not supported",
"status": 406
}

Thanks for your inputs. Will create a query in https://github.com/elastic/elasticsearch-js too as you suggested.


(Venkatesan) #7

The old version of elasticsearch.js is sending requests with application/x-ldjson which not supported by newer elasticsearch versions.

This issue got resolved after editing the package.json of node-elasticsearch-tutorial project in my local. The version of elasticsearch.js mentioned as 11.0.1 where as the latest one available is 14.0.0.

This brings me the latest version of elasticsearch.js from "npm install elasticsearch".

I am now able to index successfully using the bulk function.

Thanks.


(David Pilato) #8

That's why I wrote:

But make sure first that you are upgrading to the latest version of the JS client


(system) #9

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.