简体   繁体   中英

Is it possible to update settings and mappings of an index in elasticsearch at runtime using JAVA API

I have created an index named synonym_index using curl command

I tried the following in JAVA API

this.connection.admin().indices().prepareClose("synonym_index").execute().actionGet();
this.connection.admin().indices().prepareUpdateSettings("synonym_index").setSettings(settings).execute().actionGet();
this.connection.admin().indices().prepareOpen("synonym_index").execute().actionGet();
this.connection.admin().indices().prepareDeleteMapping("synonym_index").setType("courses").execute().actionGet();
this.connection.admin().indices().preparePutMapping("synonym_index").setType("courses").setSource(mappings).execute().actionGet();

it didn't work!! Also all my documents in the index are getting deleted !!!! Where am I going wrong?? Any ideas??

There is no way to change the types on a mapping without re-indexing your data.

There are several strategies you can use to re-index your data though -- one is deleting it, creating the mapping, then indexing it (that's what you are doing).

The second option is to use something like elasticsearch-exporter ( https://www.npmjs.org/package/elasticsearch-exporter ) to copy your data from one index to another (so create the settings/mapping you want on the new index and then copy data from old index to new). You can then setup an alias that maps the old index name to the new index name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM