elasticsearch - how to update the index setting,mapping after creating the index in elastic search on node.js -
i'm trying update setting , mapping index after creating in elastic search using node.js.when try update mapping , settings values in index not change.it remains in default settings.kindly suggest me way fix this. here mention coding.
fs.readfile('./article_settings.json', 'utf8', function (err, data) { if (err) throw err; settingsvalue = json.parse(data); console.log("settings json"); console.log(settingsvalue); return elasticclient.indices.putmapping({ index: indexname, type : type_name, body: { "settings" : settingsvalue} }); }); fs.readfile('./article_mapping.json', 'utf8', function (err, data) { if (err) throw err; mapping = json.parse(data); console.log("mapping json"); console.log(mapping); return elasticclient.indices.putmapping({ index: indexname, type : type_name, body: { "mappings":{ "articles" :{ "properties" : mapping } } } });
which produces error like.
> unhandled rejection error: indexmissingexception[[mhcarticle] missing] @ respond (/home/100095/nodesamp/mhc-search/node_modules/elasticsearch/src/lib/transport.js:264:15) @ checkrespforfailure (/home/100095/nodesamp/mhc-search/node_modules/elasticsearch/src/lib/transport.js:223:7) @ httpconnector.<anonymous> (/home/100095/nodesamp/mhc-search/node_modules/elasticsearch/src/lib/connectors/http.js:155:7) @ incomingmessage.wrapper (/home/100095/nodesamp/mhc-search/node_modules/elasticsearch/node_modules/lodash/index.js:3095:19) @ incomingmessage.eventemitter.emit (events.js:117:20) @ _stream_readable.js:920:16 @ process._tickcallback (node.js:415:13) elasticsearch debug: 2016-02-25t13:13:48z request complete elasticsearch debug: 2016-02-25t13:13:48z request complete unhandled rejection error: mapperparsingexception[root type mapping not empty after parsing! remaining fields: [mappings : {articles={properties={id={type=string, index=not_analyzed}, refference_id={type=string, index=not_analyzed}, key={type=string, index=not_analyzed}, url={type=string, index=not_analyzed}, created_on={type=string, index=not_analyzed}, status={type=string, index=not_analyzed}, title={type=string, index=not_analyzed}, description={type=string, index=not_analyzed}, batch_id={type=string, index=not_analyzed}, thumbnail={type=string, index=not_analyzed}, reference_key_id={type=string, index=not_analyzed}}}}]] @ respond (/home/100095/nodesamp/mhc-search/node_modules/elasticsearch/src/lib/transport.js:264:15) @ checkrespforfailure (/home/100095/nodesamp/mhc-search/node_modules/elasticsearch/src/lib/transport.js:223:7) @ httpconnector.<anonymous> (/home/100095/nodesamp/mhc-search/node_modules/elasticsearch/src/lib/connectors/http.js:155:7) @ incomingmessage.wrapper (/home/100095/nodesamp/mhc-search/node_modules/elasticsearch/node_modules/lodash/index.js:3095:19) @ incomingmessage.eventemitter.emit (events.js:117:20) @ _stream_readable.js:920:16 @ process._tickcallback (node.js:415:13)
kindly let me know how fix issue.thanks in advance.
after change code based on comments looks :
function initmapping(indexname,type_name){ var fs = require('fs'); var mapping; console.log(type_name); if(type_name == "articles"){ fs.readfile('./article_settings.json', 'utf8', function (err, data) { if (err) throw err; settingsvalue = json.parse(data); console.log("settings json"); console.log(settingsvalue); elasticclient.indices.close(indexname); return elasticclient.indices.putsettings({ index: indexname, type : type_name, body: { "settings" : settingsvalue} }); }); elasticclient.indices.open(indexname); fs.readfile('./article_mapping.json', 'utf8', function (err, data) { if (err) throw err; mapping = json.parse(data); console.log("mapping json"); console.log(mapping); return elasticclient.indices.putmapping({ index: indexname, type : type_name, body: { "mappings":{ "articles" :{ "properties" : mapping } } } }); }); } }
Comments
Post a Comment