美文网首页
High-Level-REST-Client 操作ES(boot

High-Level-REST-Client 操作ES(boot

作者: 李小二的倔强 | 来源:发表于2021-03-30 15:17 被阅读0次

    一、IndexRequest

    1.索引、请求的文档id、以字符串形式提供的文档源
    IndexRequest request = new IndexRequest("posts"); 
    request.id("1"); 
    String jsonString = "{" +
            "\"user\":\"kimchy\"," +
            "\"postDate\":\"2013-01-30\"," +
            "\"message\":\"trying out Elasticsearch\"" +
            "}";
    request.source(jsonString, XContentType.JSON); 
    
    2.作为映射提供的文档源,该映射将自动转换为JSON格式
    Map<String, Object> jsonMap = new HashMap<>();
    jsonMap.put("user", "kimchy");
    jsonMap.put("postDate", new Date());
    jsonMap.put("message", "trying out Elasticsearch");
    IndexRequest indexRequest = new IndexRequest("posts")
        .id("1").source(jsonMap); 
    
    3.文档源以对象密钥对的形式提供,并转换为JSON格式
    IndexRequest indexRequest = new IndexRequest("posts")
        .id("1")
        .source("user", "kimchy",
            "postDate", new Date(),
            "message", "trying out Elasticsearch"); 
    
    Optional argumentsedit-可以选择提供以下参数:

    路由值

    request.routing("routing"); 
    

    路由值

    #Timeout to wait for primary shard to become available as a TimeValue(等待主碎片作为时间值可用的超时)
    request.timeout(TimeValue.timeValueSeconds(1)); 
    #Timeout to wait for primary shard to become available as a String(等待主碎片作为字符串可用的超时)
    request.timeout("1s"); 
    
    #将策略刷新为WriteRequest.RefreshPolicy文件实例
    request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL); 
    #将策略刷新为字符串
    request.setRefreshPolicy("wait_for");                 
    
    #版本
    request.version(2); 
    
    #版本类型
    request.versionType(VersionType.EXTERNAL); 
    
    #操作类型作为DocWriteRequest.OpType文件价值
    request.opType(DocWriteRequest.OpType.CREATE); 
    #作为字符串提供的操作类型:可以创建或索引(默认)
    request.opType("create"); 
    
    #索引文档之前要执行的摄取管道的名称
    request.setPipeline("pipeline"); 
    

    相关文章

      网友评论

          本文标题:High-Level-REST-Client 操作ES(boot

          本文链接:https://www.haomeiwen.com/subject/othghltx.html