非淡泊无以明志,非宁静无以致远。这篇文章主要讲述ElasticSearch添加mapping相关的知识,希望能为你提供帮助。
1.创建索引
/**
* 创建索引
*
* @param indexName
*/
public static void createIndex(String indexName) {
//插入前删除,以免报错
boolean flag = client.admin().indices().exists(new IndicesExistsRequest().indices(new String[]{indexName})).actionGet().isExists();
if (flag){
client.admin().indices().prepareDelete(indexName).execute().actionGet();
}
client.admin().indices().prepareCreate(indexName).get();
//client.admin().indices().prepareCreate(indexName)
//.setSettings(Settings.builder()
//.put("index.number_of_shards", 3)
//.put("index.number_of_replicas", 2)
//)
//.get();
}
2.创建mapping
/** * 创建mapping,根据需求修改 * * @param indexName * @param typeName */ public static void createMapping(String indexName, String typeName) { XContentBuilder mappingType = null; try { mappingType = jsonBuilder() .startObject() .startObject(typeName) .startObject("properties") .startObject("id").field("type", "integer").field("store", "yes").endObject() .startObject("Name").field("type", "string").field("store", "yes").field("analyzer", "ik_smart").field("search_analyzer", "ik_smart").endObject() .startObject("updatedate").field("type", "date").field("store", "yes").endObject() .endObject() .endObject() .endObject(); } catch (IOException e) { logger.error("build company mapping failed", e); } PutMappingRequest mapping = Requests.putMappingRequest(indexName).type(typeName).source(mappingType); client.admin().indices().putMapping(mapping).actionGet(); client.admin().indices().prepareRefresh().get(); //client.close(); }
【ElasticSearch添加mapping】
推荐阅读
- Android Fragment和Activity的交互介绍
- 太白---落燕纷飞第一重 Android单元測试Instrumentation和irobotium
- arduinoanroid的app与arduino的ch05,进行蓝牙通信遇到的问题
- Android核心服务解析篇——Android系统的启动
- Android 相机
- Determine overlapping rectangles
- 2017四月TOP100电商类App排行榜出炉
- tomcat加载war包报错:/wls/systems/bbc-kit/apps/bbc-kit.war!/com/bbc-kit/entities/DocFile.class not found且路
- 新版App Store有哪些变化呢