@ConditionalOnMissingBean(value=ElasticService.class) public class ElasticServiceImpl extends Object implements ElasticService
| 限定符和类型 | 字段和说明 |
|---|---|
protected org.apache.commons.logging.Log |
logger |
| 构造器和说明 |
|---|
ElasticServiceImpl() |
| 限定符和类型 | 方法和说明 |
|---|---|
<T> co.elastic.clients.elasticsearch._types.Result |
addDocument(String indexName,
String id,
T t)
新增文档
|
boolean |
bulkAddDocument(co.elastic.clients.elasticsearch.core.BulkRequest.Builder builder)
批量操作新增、编辑,组装参数示例:
BulkRequest.Builder br = new BulkRequest.Builder();
for (Test8Bean product : products) {
br.operations(op -> op
.index(idx -> idx
.index("abc_test9")
.id(product.getNo())
.document(product)
)
);
}
br.build();
|
<T> boolean |
bulkAddDocument(String indexName,
List<T> list,
String key)
批量新增、修改数据操作
|
long |
count(String indexName,
co.elastic.clients.elasticsearch._types.query_dsl.Query query)
查询数量
|
boolean |
createIndex(String indexName)
创建索引,仅仅是索引名称,无任何mapping
|
boolean |
createIndex(String indexName,
InputStream input)
创建索引,带mapping的json文件流
获取mapping的json文件流示例:
ClassPathResource classPathResource = new ClassPathResource("esmapping/test8.json");
InputStream input = classPathResource.getInputStream();
|
boolean |
createIndexNoVerify(String indexName,
InputStream input)
创建索引,带mapping的json文件流[不进行重复判断,交给调用方自己判断]
获取mapping的json文件流示例:
ClassPathResource classPathResource = new ClassPathResource("esmapping/test8.json");
InputStream input = classPathResource.getInputStream();
|
co.elastic.clients.elasticsearch._types.Result |
deleteById(String indexName,
String id)
删除单条数据
|
boolean |
deleteByIds(String indexName,
List<String> ids)
批量删除数据
|
Long |
deleteByQuery(String indexName,
co.elastic.clients.elasticsearch._types.query_dsl.Query query)
根据查询条件删除数据
|
boolean |
deleteIndex(String indexName)
删除索引结构
|
boolean |
existIndex(String indexName)
验证索引是否存在
|
boolean |
existsById(String index,
String id)
验证数据是否存在
|
<T> List<T> |
getAll(String indexName,
co.elastic.clients.elasticsearch._types.query_dsl.Query query,
Class<T> cc)
获取所有数据
|
<T> T |
getById(String indexName,
String id,
Class<T> cc)
获取单条数据
|
<T> co.elastic.clients.elasticsearch.core.MgetResponse<T> |
mget(String indexName,
List<String> ids,
Class<T> cc)
根据ID批量查询
# 结果取值示例
for (MultiGetResponseItem<SiteStoreDO> doc : mgetResponse.docs()) {
SiteStoreDO source = doc.result().source();
}
|
<T> co.elastic.clients.elasticsearch.core.SearchResponse<T> |
search(co.elastic.clients.elasticsearch.core.SearchRequest request,
Class<T> tDocumentClass)
查询数据,需自己处理结果集
|
<T> List<T> |
searchList(co.elastic.clients.elasticsearch.core.SearchRequest request,
Class<T> cc)
只返回当前页结果集
|
<T> PageResult<T> |
searchPage(co.elastic.clients.elasticsearch.core.SearchRequest request,
Class<T> cc)
分页查询
|
co.elastic.clients.elasticsearch.indices.GetMappingResponse |
showIndexMapping(String indexName)
查看索引
|
<T> co.elastic.clients.elasticsearch._types.Result |
updateDocument(String indexName,
String id,
T t)
修改数据
|
Long |
updateFieldValue(String indexName,
co.elastic.clients.elasticsearch._types.query_dsl.Query query,
String field,
Object value)
更新字段的值
|
public co.elastic.clients.elasticsearch.indices.GetMappingResponse showIndexMapping(String indexName)
ElasticServiceshowIndexMapping 在接口中 ElasticServicepublic boolean existIndex(String indexName) throws IOException
existIndex 在接口中 ElasticServiceIOExceptionpublic boolean createIndex(String indexName) throws IOException
createIndex 在接口中 ElasticServiceIOExceptionpublic boolean createIndex(String indexName, InputStream input) throws IOException
获取mapping的json文件流示例:
ClassPathResource classPathResource = new ClassPathResource("esmapping/test8.json");
InputStream input = classPathResource.getInputStream();
createIndex 在接口中 ElasticServiceIOExceptionpublic boolean createIndexNoVerify(String indexName, InputStream input) throws IOException
ElasticService
获取mapping的json文件流示例:
ClassPathResource classPathResource = new ClassPathResource("esmapping/test8.json");
InputStream input = classPathResource.getInputStream();
createIndexNoVerify 在接口中 ElasticServiceIOExceptionpublic boolean deleteIndex(String indexName) throws IOException
deleteIndex 在接口中 ElasticServiceIOExceptionpublic <T> co.elastic.clients.elasticsearch._types.Result addDocument(String indexName, String id, T t) throws IOException
addDocument 在接口中 ElasticServiceIOExceptionpublic <T> co.elastic.clients.elasticsearch._types.Result updateDocument(String indexName, String id, T t) throws IOException
updateDocument 在接口中 ElasticServiceIOExceptionpublic co.elastic.clients.elasticsearch._types.Result deleteById(String indexName, String id) throws IOException
deleteById 在接口中 ElasticServiceIOExceptionpublic Long deleteByQuery(String indexName, co.elastic.clients.elasticsearch._types.query_dsl.Query query) throws IOException
deleteByQuery 在接口中 ElasticServiceIOExceptionpublic boolean deleteByIds(String indexName, List<String> ids) throws IOException
deleteByIds 在接口中 ElasticServiceIOExceptionpublic <T> boolean bulkAddDocument(String indexName, List<T> list, String key) throws Exception
bulkAddDocument 在接口中 ElasticServiceExceptionpublic boolean bulkAddDocument(co.elastic.clients.elasticsearch.core.BulkRequest.Builder builder)
throws IOException
BulkRequest.Builder br = new BulkRequest.Builder();
for (Test8Bean product : products) {
br.operations(op -> op
.index(idx -> idx
.index("abc_test9")
.id(product.getNo())
.document(product)
)
);
}
br.build();
bulkAddDocument 在接口中 ElasticServiceIOExceptionpublic boolean existsById(String index, String id) throws IOException
existsById 在接口中 ElasticServiceIOExceptionpublic <T> T getById(String indexName, String id, Class<T> cc) throws IOException
getById 在接口中 ElasticServiceIOExceptionpublic <T> co.elastic.clients.elasticsearch.core.MgetResponse<T> mget(String indexName, List<String> ids, Class<T> cc) throws IOException
# 结果取值示例
for (MultiGetResponseItem<SiteStoreDO> doc : mgetResponse.docs()) {
SiteStoreDO source = doc.result().source();
}
mget 在接口中 ElasticServiceIOExceptionpublic long count(String indexName, co.elastic.clients.elasticsearch._types.query_dsl.Query query) throws IOException
count 在接口中 ElasticServiceIOExceptionpublic <T> List<T> getAll(String indexName, co.elastic.clients.elasticsearch._types.query_dsl.Query query, Class<T> cc) throws IOException
getAll 在接口中 ElasticServiceIOExceptionpublic <T> co.elastic.clients.elasticsearch.core.SearchResponse<T> search(co.elastic.clients.elasticsearch.core.SearchRequest request,
Class<T> tDocumentClass)
throws IOException
search 在接口中 ElasticServiceIOExceptionpublic <T> PageResult<T> searchPage(co.elastic.clients.elasticsearch.core.SearchRequest request, Class<T> cc)
searchPage 在接口中 ElasticServicepublic <T> List<T> searchList(co.elastic.clients.elasticsearch.core.SearchRequest request, Class<T> cc)
searchList 在接口中 ElasticServicepublic Long updateFieldValue(String indexName, co.elastic.clients.elasticsearch._types.query_dsl.Query query, String field, Object value) throws IOException
ElasticServiceupdateFieldValue 在接口中 ElasticServiceIOException - IOExceptionCopyright © 2024 tan. All rights reserved.