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:

ClusterState cs = client.admin().cluster().prepareState().setFilterIndices("myIndex").execute().actionGet().getState();
IndexMetaData imd = cs.getMetaData().index("myIndex")
MappingMetaData mdd = imd.mapping("myType")

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..");
}
}

Add mappings to an Elasticsearch index in realtime的更多相关文章

  1. ElasticSearch Index操作源码分析

    ElasticSearch Index操作源码分析 本文记录ElasticSearch创建索引执行源码流程.从执行流程角度看一下创建索引会涉及到哪些服务(比如AllocationService.Mas ...

  2. elasticsearch index 之 put mapping

    elasticsearch index 之 put mapping   mapping机制使得elasticsearch索引数据变的更加灵活,近乎于no schema.mapping可以在建立索引时设 ...

  3. elasticsearch index tuning

    一.扩容 tag_server当前使用ElasticSearch版本为5.6,此版本单个index的分片是固定的,一旦创建后不能更改. 1.扩容方法1,不适 ES6.1支持split index功能, ...

  4. ElasticSearch Index API && Mapping

    ElasticSearch  NEST Client 操作Index var indexName="twitter"; var deleteIndexResponse = clie ...

  5. elasticsearch index 之 create index(二)

    创建索引需要创建索引并且更新集群index matedata,这一过程在MetaDataCreateIndexService的createIndex方法中完成.这里会提交一个高优先级,AckedClu ...

  6. elasticsearch index 之 create index(-)

    从本篇开始,就进入了Index的核心代码部分.这里首先分析一下索引的创建过程.elasticsearch中的索引是多个分片的集合,它只是逻辑上的索引,并不具备实际的索引功能,所有对数据的操作最终还是由 ...

  7. elasticsearch index 之 Mapping

    Lucene索引的一个特点就filed,索引以field组合.这一特点为索引和搜索提供了很大的灵活性.elasticsearch则在Lucene的基础上更近一步,它可以是 no scheme.实现这一 ...

  8. elasticsearch index 之 engine

    elasticsearch对于索引中的数据操作如读写get等接口都封装在engine中,同时engine还封装了索引的读写控制,如流量.错误处理等.engine是离lucene最近的一部分. engi ...

  9. Elasticsearch: Index template

    Index template定义在创建新index时可以自动应用的settings和mappings. Elasticsearch根据与index名称匹配的index模式将模板应用于新索引.这个对于我 ...

随机推荐

  1. BZOJ 1724 切割木板

    合并果子. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm& ...

  2. Android 框架简介--Java环境(转)

    ==========================上=========================== 这里简单的介绍了Android的java环境基础,在后面一节中会结合具体的实例来理解这一节 ...

  3. HDU 5340 Three Palindromes (Manacher)

    题意: 判断是否能将字符串S分成三段非空回文串. 思路: 先预处理出前缀回文串和后缀回文串的位置,将位置分别装入两个集合中,O(n). 针对每个前缀回文串的终点位置,挑出不相交的后缀回文串,对中间那段 ...

  4. HDU 1018 Big Number (阶乘位数)

    题意: 给一个数n,返回该数的阶乘结果是一个多少位(十进制位)的整数. 思路: 用对数log来实现. 举个例子 一个三位数n 满足102 <= n < 103: 那么它的位数w 满足 w ...

  5. 【C#学习笔记】改变字体

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. 【django】django学得好迷茫啊 来个学习规划吧

    http://www.zhihu.com/question/26235428

  7. 中小型数据库 RMAN CATALOG 备份恢复方案(二)

    中小型数据库呈现的是数据库并发少,数据库容量小,版本功能受限以及N多单实例等特点.尽管如此,数据库的损失程度也会存在零丢失的情形.企业不愿意花太多的钱又要保证数据库的可靠稳定,可是苦煞了我这些搞DB的 ...

  8. Mysql 不同版本 说明

    Mysql 的官网下载地址: http://dev.mysql.com/downloads/ 在这个下载界面会有几个版本的选择. 1. MySQL Community Server 社区版本,免费,但 ...

  9. .vdat文件怎么打开

    http://tieba.baidu.com/p/2947300642 无需转换,把后缀修改为MP4,就可以了

  10. javascript中createTextRange用法(focus)

    createtextrange createrange区别: 对象或元素不同,虽然都是返回TextRange.例如:     var r=document.body.createTextRange() ...