一戒财、IndexRequest
1.索引、請(qǐng)求的文檔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.作為映射提供的文檔源饮寞,該映射將自動(dòng)轉(zhuǎn)換為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.文檔源以對(duì)象密鑰對(duì)的形式提供,并轉(zhuǎn)換為JSON格式
IndexRequest indexRequest = new IndexRequest("posts")
.id("1")
.source("user", "kimchy",
"postDate", new Date(),
"message", "trying out Elasticsearch");
Optional argumentsedit-可以選擇提供以下參數(shù):
路由值
request.routing("routing");
路由值
#Timeout to wait for primary shard to become available as a TimeValue(等待主碎片作為時(shí)間值可用的超時(shí))
request.timeout(TimeValue.timeValueSeconds(1));
#Timeout to wait for primary shard to become available as a String(等待主碎片作為字符串可用的超時(shí))
request.timeout("1s");
#將策略刷新為WriteRequest.RefreshPolicy文件實(shí)例
request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);
#將策略刷新為字符串
request.setRefreshPolicy("wait_for");
#版本
request.version(2);
#版本類型
request.versionType(VersionType.EXTERNAL);
#操作類型作為DocWriteRequest.OpType文件價(jià)值
request.opType(DocWriteRequest.OpType.CREATE);
#作為字符串提供的操作類型:可以創(chuàng)建或索引(默認(rèn))
request.opType("create");
#索引文檔之前要執(zhí)行的攝取管道的名稱
request.setPipeline("pipeline");