赞
踩
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,搜索条件拼接
.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);
效果如下
{"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"}}]}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。