ElasticSearch 实现分词全文检索 - filter查询
目录
ElasticSearch 实现分词全文检索 - 概述
ElasticSearch 实现分词全文检索 - ES、Kibana、IK安装
ElasticSearch 实现分词全文检索 - Restful基本操作
ElasticSearch 实现分词全文检索 - Java SpringBoot ES 索引操作
ElasticSearch 实现分词全文检索 - Java SpringBoot ES 文档操作
ElasticSearch 实现分词全文检索 - 测试数据准备
ElasticSearch 实现分词全文检索 - term、terms查询
ElasticSearch 实现分词全文检索 - match、match_all、multimatch查询
ElasticSearch 实现分词全文检索 - id、ids、prefix、fuzzy、wildcard、range、regexp 查询
ElasticSearch 实现分词全文检索 - Scroll 深分页
ElasticSearch 实现分词全文检索 - delete-by-query
ElasticSearch 实现分词全文检索 - 复合查询
ElasticSearch 实现分词全文检索 - filter查询
ElasticSearch 实现分词全文检索 - 高亮查询
ElasticSearch 实现分词全文检索 - 聚合查询 cardinality
ElasticSearch 实现分词全文检索 - 经纬度查询
ElasticSearch 实现分词全文检索 - 搜素关键字自动补全(suggest)
ElasticSearch 实现分词全文检索 - SpringBoot 完整实现 Demo 附源码
query,根据查询条件,去计算文档的匹配度得到一个分数,并且根据分数进行排序,不会做缓存。【精准匹配度高】
filter,根据查询条件去查询文档,不去计算分数,而且filter会对经常被过滤的数据进行缓存。【查询效率会高】
# filter 查询
POST /sms-logs-index/_search
{
"query": {
"bool": {
"filter": [
{
"term": {
"corpName": "阿里3"
}
},
{
"range": {
"fee": {
"gte": 20
}
}
}
]
}
}
}
Java
@Test
void filterQuery() throws Exception {
String indexName = "sms-logs-index";
RestHighLevelClient client = ESClient.getClient();
//1. 创建SearchRequest对象
SearchRequest request = new SearchRequest(indexName);
//2. 指定查询条件
SearchSourceBuilder builder = new SearchSourceBuilder();
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.filter(QueryBuilders.termQuery("corpName","阿里3"));
boolQuery.filter(QueryBuilders.rangeQuery("fee").gte(20));
builder.query(boolQuery);
request.source(builder);
//3. 执行查询
SearchResponse resp = client.search(request, RequestOptions.DEFAULT);
//4. 输出返回值
for (SearchHit hit : resp.getHits().getHits()) {
System.out.println(hit.getSourceAsMap());
}
}
本文来自博客园,作者:VipSoft 转载请注明原文链接:https://www.cnblogs.com/vipsoft/p/17171243.html