spring:
elasticsearch:
port: 9200
host: 192.168.151.234
thread:
corePoolSize: 2
maxPoolSize: 4
keepAliveSeconds: 30
queueCapacity: 50
例如:
@EsIndexMaintenance(type = OperationTypeEnum.ADD,
indexName = "test-index",
indexId = "#tests.![id]",
doc = {
"#tests.![id]",
"#tests.![name]",
"#tests.![age]"
},
docField = {
"id",
"name",
"age"
})
public boolean saveBatch(List<TestDO> tests) {
return true;
}
@EsIndexMaintenance(type = OperationTypeEnum.DELETE,
indexName = "test-index",
indexId = "#ids")
public boolean deleteByIds(List<String> ids) {
return true;
}
@EsIndexMaintenance(type = OperationTypeEnum.DELETE,
indexName = "test-index",
indexId = "#id")
public boolean deleteById(String id) {
return true;
}
规则:
- indexName为es目标文档索引名
- indexId、doc为Spel表达式
- docField为目标文档的关键字需与doc数组一一对应
实现该步骤即集成完成了es文档自动维护
搜索查询对象:
public class EsSearchQuery {
/**
* 关键字
*/
private String keyWord;
/**
* 当前页
*/
private Integer pageIndex = 1;
/**
* 每页数据量
*/
private Integer pageSize = 10;
}
搜索方法:
public interface EsSearchService {
/**
* 搜索方法
* @param query 查询条件
* @param keyWordObject 文档关键字对象
* @param response 查询出来的结果文档
* @param indexName 索引值
* @param <T>
* @return
*/
<T extends SearchResultData> EsSearchResultData<T> search(EsSearchQuery query, Class<?> keyWordObject, Class<T> response, String... indexName);
}
规则:
-
keyWordObject为需要查询的关键字对象,例如我有一个文档里面的关键字为name、age、sex,我想要本次查询name和age关键字,则定义类:
public class TestKeyData{ private String name; private Integer age; }
-
response为本次查询的响应结果类
-
indexName为本次查询的目标文档名,支持多个文档复合查询