背景
本文记录使用es过程中的学习记录
其java api 可以参考官网文档如下
Index API | Java REST Client [7.5] | Elastic
1. IndexRequest
相关
该方式是新建索引api,如存在相同的id,则会覆盖掉
使用bulk批量调用es,或新增或删除
例如
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(new DeleteRequest("myIndex", "myDoc", "1"));
bulkRequest.add(new UpdateRequest("myIndex", "myDoc", "2").doc(XContentType.JSON,"other", "test").fetchSource(true));
bulkRequest.add(new IndexRequest("myIndex")
.id("1")
.source("user", "kimchy",
"postDate", new Date(),
"message", "trying out Elasticsearch"););
/**public IndexRequest source(String source, XContentType xContentType) {
return this.source((BytesReference)(new BytesArray(source)), (XContentType)xContentType);
}**/
//, XContentType.JSON
根据 BulkItemResponse获取执行的结果
失败 getFailure
成功 getResponse.getResult()
2. 查询 filter 和 must 区别
must效率低,因其需要打分,filter 不需要
must 和filter是同一级别的查询,在bool中
Get /product/_search
{
"query": {
"bool" : {
"must" :
"should" :
"must_not" :
"filter":
}
}
}