feat: There is no way the, 文本索引 根据条件查询 更新索引数据

This commit is contained in:
super_liu
2022-05-09 16:24:39 +08:00
parent 705c115db3
commit 7c21d67edf
7 changed files with 381 additions and 6 deletions
@@ -122,7 +122,7 @@ public interface ElasticsearchService {
* 使用索引查询所有
*/
List<Map<String,Object>> searchAll(String index);
List<Map<String,Object>> searchAll(String index,String search);
/**
* 使用分词查询
@@ -284,7 +284,7 @@ public class ElasticsearchServiceImpl implements ElasticsearchService {
* 使用索引查询所有
*/
@Override
public List<Map<String, Object>> searchAll(String index) {
public List<Map<String, Object>> searchAll(String index,String search) {
List<Map<String, Object>> sourceList = new ArrayList<Map<String, Object>>();
//1、指定es集群 cluster.name 是固定的key值,my-application是ES集群的名称
@@ -295,7 +295,18 @@ public class ElasticsearchServiceImpl implements ElasticsearchService {
.get();
SearchHits hits = sResponse.getHits();
if(hits.getTotalHits().value > 0){
SearchResponse scrollResp = search(index,qBuilder, 1,(int) hits.getTotalHits().value);
BoolQueryBuilder boolSelectValue = new BoolQueryBuilder();
if(StringUtils.isNotBlank(search)){
boolSelectValue
.should(QueryBuilders.wildcardQuery("sortTitle.keyword", "*" + search.toUpperCase() + "*").boost(1005f))
.should(QueryBuilders.wildcardQuery("numberTitle.keyword", "*" + search.toUpperCase() + "*").boost(1003f))
.should(QueryBuilders.wildcardQuery("yearOrder.keyword", "*" + search.toUpperCase() + "*").boost(1002f))
.should(QueryBuilders.wildcardQuery("nameTitle.keyword", "*" + search.toUpperCase() + "*").boost(1001f))
.should(QueryBuilders.wildcardQuery("title.keyword", "*" + search + "*").boost(1000f))
.should(QueryBuilders.wildcardQuery("textContent.keyword", "*" + search.toUpperCase() + "*").boost(0.0000000000000000000000000000000001f))
.should(QueryBuilders.wildcardQuery("issue_time", "*" + search.toUpperCase() + "*"));
}
SearchResponse scrollResp = search(index,boolSelectValue, 1,(int) hits.getTotalHits().value);
for (SearchHit hit : scrollResp.getHits().getHits()) {
sourceList.add(hit.getSourceAsMap());
}