ElasticSearch添加映射
调用client.admin().indices().putMapping(mapping).get()来完成映射的添加。
@Test
// 映射操作
public void demo5() throws IOException, InterruptedException,
ExecutionException {
// 创建连接搜索服务器对象
Client client = TransportClient
.builder()
.build()
.addTransportAddress(
new InetSocketTransportAddress(InetAddress
.getByName("127.0.0.1"), 9300));
// 添加映射
XContentBuilder builder = XContentFactory.jsonBuilder().startObject()
.startObject("article").startObject("properties")
.startObject("id").field("type", "integer")
.field("store", "yes").endobject().startObject("title")
.field("type", "string").field("store", "yes")
.field("analyzer", "ik").endobject().startObject("content")
.field("type", "string").field("store", "yes")
.field("analyzer", "ik").endobject().endobject().endobject()
.endobject();
PutMappingRequest mapping = Requests.putMappingRequest("blog2")
.type("article").source(builder);
client.admin().indices().putMapping(mapping).get();
// 关闭连接
client.close();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。