ElasticSearch添加映射
生活随笔
收集整理的這篇文章主要介紹了
ElasticSearch添加映射
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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(); }總結
以上是生活随笔為你收集整理的ElasticSearch添加映射的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: elasticsearch手动创建和删除
- 下一篇: ElasticSearch创建文档