Add mappings to an Elasticsearch index in realtime
2013-10-15 08:59
627 查看
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:
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
- HBaseCon 2013: Using Coprocessors to Index Columns in an Elasticsearch Cluster
- Introduction to Elasticsearch in PHP
- 关于VC++6.0加载控件出现Unable to register this add-in because its DllRegisterServer returns an error 的解决方法
- Programmatically add credentials to an ASMX Web Service that is password protected in C#
- VC++ Unable to register this add-in because its DllRegisterServer returns an error 解决方案(转载)
- Is there a way to add a badge to an application icon in Android?
- WIN7下VC6.0无法使用打开功能(Unable to register this add-in because its DLLRegisterServer return an error)
- Know How To Use ID_NULL Function To Search An Object In Oracle Forms
- WIN7下VC6.0无法使用打开功能(Unable to register this add-in because its DLLRegisterServer return an error)
- simulation is not running in real time due to excessive cpu load
- Is there a way to add a badge to an application icon in Android?
- Creating a real-time search engine with IndexTank and Heroku
- How to hide an entry in the Add/Remove Programs applet?
- Mapping an NCLOB to a String property in NHibernate
- How to read out WhatsApp messages with Tasker and react on their content in real time
- How to Save an ARIMA Time Series Forecasting Model in Python (如何在Python中保存ARIMA时间序列预测模型)
- unable to register this add-in because its dllregisterserver returns an error解决方案
- Divide and Conquer (1) -- Kth Largest Element in an Array,Different Ways to Add Parentheses
- WIN7下VC6.0无法使用打开文件功能(Unable to register this add-in because its DLLRegisterServer return an error)