----------------------------------------------------------------------------------
SearchRequest:查询请求
SearchRequest searchRequest = new SearchRequest();
它提供的常用方法:
SearchRequest source(SearchSourceBuilder sourceBuilder)
----------------------------------------------------------------------------------
SearchSourceBuilder:查询请求体构建器-->用于承载各种构建器
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
它提供的常用方法:
//将聚合生成器加入请求体
SearchSourceBuilder aggregation(AggregationBuilder aggregation)
//将高亮构建器加入请求体
SearchSourceBuilder highlighter(HighlightBuilder highlightBuilder)
//分页查询时设定起始索引
SearchSourceBuilder from(int from)
//分页查询时设定每页数据量
SearchSourceBuilder size(int size)
----------------------------------------------------------------------------------
QueryBuilder:查询构建器接口
QueryBuilders用于提供QueryBuilder接口的实现类实例对象
QueryBuilders提供的常用方法如下:
//复合查询
BoolQueryBuilder boolQuery()
//匹配全部文档-->https://www.cnblogs.com/sbj-dawn/p/8891419.html
MatchAllQueryBuilder matchAllQuery()
//匹配字段名为name,值为value或其分词结果的的文档-->https://www.cnblogs.com/sbj-dawn/p/8891419.html
MatchQueryBuilder matchQuery(String name, Object text)
//匹配字段filed1或field2...或fieldN中包含text的文档(必须与text一致)-->https://www.cnblogs.com/sbj-dawn/p/8891419.html
MultiMatchQueryBuilder multiMatchQuery(Object text, String... fieldNames)
//模糊查询,?匹配单个字符,*匹配多个字符-->EP:("name","*jack*")-->搜索名字中含有jack文档(name中只要包含jack即可)
WildcardQueryBuilder wildcardQuery(String name, String query)
//完全匹配字段名为name,值为value的文档
TermQueryBuilder termQuery(String name, String value)
//指定字段名为name的大于等于from的范围
RangeQueryBuilder rangeQuery(String name).gte(Object from)
//指定字段名为name的小于于等于from的范围
RangeQueryBuilder rangeQuery(String name).lte(Object from)
----------------------------------------------------------------------------------
BoolQueryBuilder:组合查询构建器
//过滤
BoolQueryBuilder filter(QueryBuilder queryBuilder)
//获取组合中所有用于过滤的构建器
List<QueryBuilder> filter()
//AND关系(必须满足参数构建器的查询条件)
BoolQueryBuilder must(QueryBuilder queryBuilder)
//OR关系(或者满足参数构建器的查询条件)
BoolQueryBuilder should(QueryBuilder queryBuilder)
//NOT关系(必须不满足参数构建器的查询条件)
BoolQueryBuilder mustNot(QueryBuilder queryBuilder)
----------------------------------------------------------------------------------
HighlightBuilder:高亮构建器
HighlightBuilder field(String name)
****
HighlightBuilder extends AbstractHighlighterBuilder<HighlightBuilder>
****
AbstractHighlighterBuilder<HB>中相关常用方法:
HB preTags(String... preTags)
HB postTags(String... postTags)
----------------------------------------------------------------------------------
聚合查询构建器
/*
"aggs": {
"参数name": {
"terms": {
"field":"参数field"
}
}
}
*/
TermsAggregationBuilder AggregationBuilders.terms(String name).field(String field)
----------------------------------------------------------------------------------