首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > 云计算 >

Add 地图pings to an Elasticsearch index in realtime

2013-10-15 
Add mappings to an Elasticsearch index in realtimeChanging mapping on existing index is not an easy

Add mappings to an Elasticsearch index in realtime

Changing mapping on existing index is not an easy task. You may find the reason and possible solutions in here:

http://www.elasticsearch.org/blog/changing-mapping-with-zero-downtime/



to get current mapping details, here is the sample code:

Put Mappings In Real time:

private void putMapping() {    if (client != null) {       if (client.admin().indices().prepareExists(IndexName).execute().actionGet().isExists()) {          XContentBuilder mappings = null;          try {             mappings = XContentFactory.jsonBuilder().startObject()    .startObject(INDEX_TYPE)        .startObject("properties").startObject(FIELD_NAME)        .field("type","string")       .field("store","yes") .field("index", "analyzed") .field("analyzer", "simple").endObject()        .endObject()      .endObject().endObject();          } catch (IOException e) {     e.printStackTrace();          }          client.admin().indices().prepareClose(IndexName).execute().actionGet();          client.admin().indices().prepareDeleteMapping(IndexName).setType(INDEX_TYPE).execute().actionGet();          client.admin().indices().preparePutMapping(IndexName).setIgnoreConflicts(true).setType(INDEX_TYPE).setSource(mappings).execute().actionGet();  client.admin().indices().prepareOpen(IndexName).execute().actionGet();       }    } else {throw new IllegalStateException(" Elastic Search not initialized properly..");    }}


热点排行