I am working on chat application, i need to push chat information to elasticsearch for specified index using nodejs.
I have cretaed index and push data to elasticsearch using below code.
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
client.ping({
requestTimeout: 30000,
// undocumented params are appended to the query string
hello: "elasticsearch"
}, function (error) {
if (error) {
console.error('elasticsearch cluster is down!');
} else {
console.log('All is well');
}
});
var result = client.index({
index: 'chennaiboxchat',
type: 'posts',
id: '1',
body: {
"glossary": {
"title": "example Test",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "mark"
}
}
}
}
},
refresh: true
});
But, if I run this code next time overwrite the data.so, I need to Update the data in same index in elasticsearch using Nodejs. Suggest me how to update data in single index.