这里写目录标题
一、文档APIs
Java 高级 REST 客户端支持以下文档 API:
1.单文档 API
Index API
1.IndexRequest
1.一个IndexRequest需要以下参数:
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); //参数三
指数
请求的文档 ID
提供的文档来源String
2.提供文件来源
String除了上面显示的示例之外,还可以通过不同的方式提供文档源 :
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); // 提供的文档源Map自动转换为 JSON 格式
XContentBuilder builder = XContentFactory.jsonBuilder(