public interface ElasticService
| 限定符和类型 | 方法和说明 |
|---|---|
<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)
更新字段的值
|
co.elastic.clients.elasticsearch.indices.GetMappingResponse showIndexMapping(String indexName)
boolean existIndex(String indexName) throws IOException
IOExceptionboolean createIndex(String indexName) throws IOException
IOExceptionboolean createIndex(String indexName, InputStream input) throws IOException
获取mapping的json文件流示例:
ClassPathResource classPathResource = new ClassPathResource("esmapping/test8.json");
InputStream input = classPathResource.getInputStream();
IOExceptionboolean createIndexNoVerify(String indexName, InputStream input) throws IOException
获取mapping的json文件流示例:
ClassPathResource classPathResource = new ClassPathResource("esmapping/test8.json");
InputStream input = classPathResource.getInputStream();
IOExceptionboolean deleteIndex(String indexName) throws IOException
IOException<T> co.elastic.clients.elasticsearch._types.Result addDocument(String indexName, String id, T t) throws IOException
IOException<T> co.elastic.clients.elasticsearch._types.Result updateDocument(String indexName, String id, T t) throws IOException
IOExceptionco.elastic.clients.elasticsearch._types.Result deleteById(String indexName, String id) throws IOException
IOExceptionLong deleteByQuery(String indexName, co.elastic.clients.elasticsearch._types.query_dsl.Query query) throws IOException
IOExceptionboolean deleteByIds(String indexName, List<String> ids) throws IOException
IOException<T> boolean bulkAddDocument(String indexName, List<T> list, String key) throws Exception
Exceptionboolean 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();
IOExceptionboolean existsById(String index, String id) throws IOException
IOException<T> T getById(String indexName, String id, Class<T> cc) throws IOException
IOException<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();
}
IOExceptionlong count(String indexName, co.elastic.clients.elasticsearch._types.query_dsl.Query query) throws IOException
IOException<T> List<T> getAll(String indexName, co.elastic.clients.elasticsearch._types.query_dsl.Query query, Class<T> cc) throws IOException
IOException<T> co.elastic.clients.elasticsearch.core.SearchResponse<T> search(co.elastic.clients.elasticsearch.core.SearchRequest request,
Class<T> tDocumentClass)
throws IOException
IOException<T> PageResult<T> searchPage(co.elastic.clients.elasticsearch.core.SearchRequest request, Class<T> cc)
<T> List<T> searchList(co.elastic.clients.elasticsearch.core.SearchRequest request, Class<T> cc)
Long updateFieldValue(String indexName, co.elastic.clients.elasticsearch._types.query_dsl.Query query, String field, Object value) throws IOException
IOException - IOExceptionCopyright © 2024 tan. All rights reserved.