zoukankan      html  css  js  c++  java
  • es6.6.1 java客户端 client基础操作

    1.引入jar包

    <dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>elasticsearch-rest-high-level-client</artifactId>
    <version>6.6.1</version>
    </dependency>

    2.测试demo

    public static void main( String[] args ) throws IOException
        {
            
            RestHighLevelClient client = new RestHighLevelClient(
                    RestClient.builder(
                    new HttpHost("192.168.249.129", 9200, "http")));
            
    //        //创建索引
    //        IndexRequest indexRequest = new IndexRequest("product", "car", "1");
    //        //索引index(四种json,map,XContentBuilder,object)
    //        Map<String, Object> source = new HashMap<String, Object>();
    //        source.put("字段1", "值1");
    //        source.put("字段2", new Date());
    //        source.put("字段3", "值2");
    //        indexRequest.source(source);
    //        IndexResponse indexResponse = client.index(indexRequest,RequestOptions.DEFAULT);
    //        System.out.println(indexResponse.getResult());
    //        
            //删除
            DeleteRequest deleteRequest = new DeleteRequest("product", "car", "1");
            DeleteResponse deleteResponse = client.delete(deleteRequest,RequestOptions.DEFAULT);
            System.out.println(deleteResponse.getResult());
            
            //查询
            GetRequest getRequest = new GetRequest("product", "car", "1");
            GetResponse getResponse = client.get(getRequest,RequestOptions.DEFAULT);
            System.out.println(getResponse.getSourceAsString());
            
    //        判断exist
    //        boolean exists = client.exists(getRequest, RequestOptions.DEFAULT);
    //        System.out.println("exists="+exists);
            
            //更新
    //        UpdateRequest updateRequest = new UpdateRequest("product", "car", "1");
    //          Map<String, Object> source = new HashMap<String, Object>();
    //          source.put("字段11", "值1");
    //          source.put("字段22", new Date());
    //          source.put("字段33", "值2");
    //          updateRequest.doc(source);
    //        UpdateResponse updateResponse = client.update(updateRequest,RequestOptions.DEFAULT);
    //        System.out.println(updateResponse.getResult());
            
            
            client.close();
        }
  • 相关阅读:
    K8S集群组件
    K8S概念
    yaml格式
    Linux下升级openssl
    cpu的核心数及线程关系
    bzoj4941: [Ynoi2016]镜子里的昆虫
    bzoj4940: [Ynoi2016]这是我自己的发明
    bzoj4939: [Ynoi2016]掉进兔子洞
    bzoj4867: [Ynoi2017]舌尖上的由乃
    bzoj 4866: [Ynoi2017]由乃的商场之旅
  • 原文地址:https://www.cnblogs.com/oktokeep/p/14370410.html
Copyright © 2011-2022 走看看