Elasticsearch常用API粗略笔记

----------------------------------------------------------------------------------


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)

----------------------------------------------------------------------------------


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值