I need to index multiple jsons in elasticsearch and indexing id should be given by user not by automatically created by elasticserach.
Can any please tell me how to stop elasticsearch from creating automatic index id and how can I use my desired id for data indexing.
Below is the part of node.js code for indexing data:
elasticSearchClient.index('index_name', 'type', json)
.on('data', function(data) {
console.log("************ "+data+" ****************")
})
.exec()
Any help will be greatly appreciated!
Regards
If we don't give indexing id then indexing id for document will be auto created by elasticsearch.
So I use below code and tell the indexing id for indexing doc.
var commands = []
commands.push({ "index" : { "_index" :'opt', "_type" : "art", "_id":my_id} })
commands.push(index_ingjson_doc)
elasticSearchClient.bulk(commands, {})
.on('data', function(data) {
}).on('error', function(error){})
.exec();
In this way, I resolved my problem! Some other solutions may be possible but as of now I am using above code.
If I'm understanding you correctly, just put "_id": whatever
into your JSON and ensure index.mapping._id.indexed
is set to true
.
Just include the id
field in your json document. It will be automatically extracted from the document and put in the url. In fact the core.js script contains this logic:
if (document.id) {
path += "/" + document.id
method = 'PUT'
delete document.id
}
elasticSearchClient.bulk() is the solution for my problem.
Reference: https://github.com/phillro/node-elasticsearch-client