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:
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的更多相关文章
- ElasticSearch Index操作源码分析
ElasticSearch Index操作源码分析 本文记录ElasticSearch创建索引执行源码流程.从执行流程角度看一下创建索引会涉及到哪些服务(比如AllocationService.Mas ...
- elasticsearch index 之 put mapping
elasticsearch index 之 put mapping mapping机制使得elasticsearch索引数据变的更加灵活,近乎于no schema.mapping可以在建立索引时设 ...
- elasticsearch index tuning
一.扩容 tag_server当前使用ElasticSearch版本为5.6,此版本单个index的分片是固定的,一旦创建后不能更改. 1.扩容方法1,不适 ES6.1支持split index功能, ...
- ElasticSearch Index API && Mapping
ElasticSearch NEST Client 操作Index var indexName="twitter"; var deleteIndexResponse = clie ...
- elasticsearch index 之 create index(二)
创建索引需要创建索引并且更新集群index matedata,这一过程在MetaDataCreateIndexService的createIndex方法中完成.这里会提交一个高优先级,AckedClu ...
- elasticsearch index 之 create index(-)
从本篇开始,就进入了Index的核心代码部分.这里首先分析一下索引的创建过程.elasticsearch中的索引是多个分片的集合,它只是逻辑上的索引,并不具备实际的索引功能,所有对数据的操作最终还是由 ...
- elasticsearch index 之 Mapping
Lucene索引的一个特点就filed,索引以field组合.这一特点为索引和搜索提供了很大的灵活性.elasticsearch则在Lucene的基础上更近一步,它可以是 no scheme.实现这一 ...
- elasticsearch index 之 engine
elasticsearch对于索引中的数据操作如读写get等接口都封装在engine中,同时engine还封装了索引的读写控制,如流量.错误处理等.engine是离lucene最近的一部分. engi ...
- Elasticsearch: Index template
Index template定义在创建新index时可以自动应用的settings和mappings. Elasticsearch根据与index名称匹配的index模式将模板应用于新索引.这个对于我 ...
随机推荐
- 自己实现字符串操作函数strlen(),strcat(),strcpy(),strcmp()
1.strlen()函数是求解字符串的有效长度的 1)非递归实现 size_t my_strlen(const char *str) { assert(str != NULL); //断言,保证指针 ...
- [反汇编练习] 160个CrackMe之025
[反汇编练习] 160个CrackMe之025. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...
- scala学习笔记(9):Scala函数(2)
1 指令式编程&函数式编程 指令式:imperative 风格编程.指令式风格,是你常常使用像 Java,C++和 C 这些语言里用的风格,一次性发出一个指令式的命令,用循环去枚举,并经常改变 ...
- AJax学习一
1.Ajax的准备工作,就是要先准备好服务器环境. 这边可以有好几种方式,例如服务器工具: http://www.php100.com/html/plugin/ser/2013/0905/91.htm ...
- unittest框架的注意点
这篇并不是讲unittest如何使用,而是记录下在和htmltestrunner集成使用过程中遇到的一些坑,主要是报告展示部分. 我们都知道python有一个单元测试框架pyunit,也叫unitte ...
- VC6兼容性及打开文件崩溃问题解决
VC6虽然老,但是一些工程还非得用它打开,没办法…… 今天偶然用到,因为新装了系统,之前的问题又要重新解决一遍 在这记录下解决过程,方便以后查阅: 一.兼容问题: XP以上windows系统打开VC6 ...
- ps闪闪发光的字 教程+自我练习
本教程的文字效果非常经典.不仅是效果出色,创作思路及制作手法都堪称完美.作者并没有直接使用纹理素材,纹理部分都是用滤镜来完成.这需要很强的综合能力,非常值得学习和借鉴.最终效果 我的: 1.创建一个新 ...
- RFID之UID
1 Unique identifier (UID) The VICCs are uniquely identified by a 64 bits unique identifier (UID). Th ...
- AutoCompleteTextView使用 监听
AutoCompleteTextView使用 An editable text view that shows completion suggestions automatically while t ...
- Office2016 转换零售版为VOL版
@echo off :ADMIN openfiles >nul >nul ||( echo Set UAC = CreateObject^("Shell.Application& ...