zoukankan      html  css  js  c++  java
  • ElasticSearch 批量增加索引

    服务端批量增加索引,版本是5.1.1

    TransportClient client;
            Settings esSettings = Settings.builder()
                    .put("cluster.name", "elasticsearch") //设置ES实例的名称
                    .put("client.transport.sniff", true) //自动嗅探整个集群的状态,把集群中其他ES节点的ip添加到本地的客户端列表中
                    .build();
            client = new PreBuiltTransportClient(esSettings);//初始化client较老版本发生了变化,此方法有几个重载方法,初始化插件等。
            //此步骤添加IP,至少一个,其实一个就够了,因为添加了自动嗅探配置
            try {
                client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
    
            Map<String,Object> infoMap = new HashMap<String, Object>();
            infoMap.put("name", "广告信息11");
    
            Map<String,Object> infoMap2 = new HashMap<String, Object>();
            infoMap.put("name", "广告信息22");
    
            IndexRequest indexRequest = new IndexRequest("index","type","5");
            indexRequest.source(infoMap);
            BulkRequestBuilder bulk = client.prepareBulk();
            bulk.add(indexRequest);
    
            IndexRequest indexRequest1 = new IndexRequest("index","type","6");
            indexRequest1.source(infoMap2);
            bulk.add(indexRequest1);
    
            BulkResponse bulkResponse = bulk.execute().actionGet();

    这样就会把索引写入。

  • 相关阅读:
    Extjs 4.0 Grid 数据绑定 json 分页 不分页
    [转]AS语言基础
    tig支持中文搜索
    LPC及MudOS简介(一)
    欢送2012
    存储器性能测试
    为什么go语言适合开发网游服务器端
    从一段代码里看FreeBSD与Linux内存分配的不同
    新的开始
    多语言协作与二进制交互
  • 原文地址:https://www.cnblogs.com/zhangjwcode/p/7657093.html
Copyright © 2011-2022 走看看