1,根据字段数据去重 ?
CollapseBuilder collapseBuilder = new CollapseBuilder("?");
sourceBuilder.collapse(collapseBuilder);
2,排序
super.sourceBuilder.sort(SortBuilders.fieldSort("createTime").order(SortOrder.DESC));
3,设置搜索分页
sourceBuilder.from((searchDto.getPageIndex() - 1) * searchDto.getPageSize()).size(searchDto.getPageSize());
4,搜索条件拼接文章来源:https://www.toymoban.com/news/detail-809216.html
.boost() 设置条件等级 .caseInsensitive(true)忽略查询大小写
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder()
.must(QueryBuilders.boolQuery()
.must(QueryBuilders.boolQuery()
.should(QueryBuilders.wildcardQuery("title.keyword", searchDto.getKeyword()).boost(5).caseInsensitive(true))
.should(QueryBuilders.wildcardQuery("title.keyword", key).caseInsensitive(true)))
.must(QueryBuilders.boolQuery()
.should(QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("historyIsDelete", false))
.must(QueryBuilders.termQuery("typeId", "1"))
.must(QueryBuilders.termQuery("playBackRecording", 1))
.must(QueryBuilders.rangeQuery("saveRecordingTime").gte(time))
.must(QueryBuilders.termQuery("transcodingStatus", 1)))
.should(QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("channelIsDelete", false))
// .must((QueryBuilders.rangeQuery("beginTime").gte(date)))
.must((QueryBuilders.boolQuery().should((QueryBuilders.rangeQuery("liveBeginTime").gte(date)))
.should(QueryBuilders.termQuery("isReserve", 1))))))
);
sourceBuilder.query(boolQueryBuilder);
效果如下文章来源地址https://www.toymoban.com/news/detail-809216.html
{"from":0,"size":4,"query":{"bool":{"must":[{"bool":{"must":[{"bool":{"should":[{"wildcard":{"title.keyword":{"wildcard":"2023","case_insensitive":true,"boost":5.0}}},{"wildcard":{"title.keyword":{"wildcard":"*2023*","case_insensitive":true,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}},{"bool":{"should":[{"bool":{"must":[{"term":{"historyIsDelete":{"value":false,"boost":1.0}}},{"term":{"typeId":{"value":"1","boost":1.0}}},{"term":{"playBackRecording":{"value":1,"boost":1.0}}},{"range":{"saveRecordingTime":{"from":1676451404,"to":null,"include_lower":true,"include_upper":true,"boost":1.0}}},{"term":{"transcodingStatus":{"value":1,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}},{"bool":{"must":[{"term":{"channelIsDelete":{"value":false,"boost":1.0}}},{"bool":{"should":[{"range":{"liveBeginTime":{"from":"2023-02-15T08:56:44.723Z","to":null,"include_lower":true,"include_upper":true,"boost":1.0}}},{"term":{"isReserve":{"value":1,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"sort":[{"createTime":{"order":"desc"}}]}
到了这里,关于java-es 搜索条件拼接 SearchSourceBuilder的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!