简体   繁体   English

Elasticsearch 过滤结果忽略搜索关键字

[英]Elasticsearch filter result ignoring search keyword

I am getting good result with normal search query.我通过正常的搜索查询得到了很好的结果。

SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
BoolQueryBuilder queryBuilder = new BoolQueryBuilder();

 String keyword = requestBody.getKeyword();

 queryBuilder.should(QueryBuilders.matchQuery("fullText", keyword));

 searchSourceBuilder.query(queryBuilder);
 searchSourceBuilder.from(requestBody.getPage() - 1);
 searchSourceBuilder.size(BROWSE_PAGE_DATA_LIMIT);

 searchRequest.source(searchSourceBuilder);

    try {
        return client.search(searchRequest, RequestOptions.DEFAULT);
    } catch (IOException e) {
        throw new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Error in ES search");
    }

But when I add filtering with it, the result is ignoring my search keyword.但是当我用它添加过滤时,结果是忽略了我的搜索关键字。

queryBuilder.filter(QueryBuilders.termsQuery("authorId", filter.getAuthorIds()));

here I am trying to replace fq of solr.在这里,我试图替换 solr 的 fq。 What's wrong at my approach.我的方法有什么问题。

Excerpt from ES Docs摘自ES 文档

If the bool query includes at least one should clause and no must or filter clauses, the default value is 1. Otherwise, the default value is 0.如果 bool 查询包含至少一个 should 子句且没有 must 或 filter 子句,则默认值为 1。否则,默认值为 0。

Basically, if there is a filter or/and must clause with-in a bool query then the should clause is ignored until min_should_match is set to a suitable value.基本上,如果在 bool 查询中存在过滤器或/和 must 子句,则忽略 should 子句,直到将 min_should_match 设置为合适的值。

Set minShouldMatch to 1. eg:将 minShouldMatch 设置为 1。例如:

queryBuilder.should(QueryBuilders.matchQuery("fullText", keyword)).minimumShouldMatch(1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Spring Data Elasticsearch 搜索和过滤 - Search and filter with Spring Data Elasticsearch Elasticsearch:完全禁用IDF以进行搜索结果评分 - Elasticsearch : Disable IDF completely for search result scoring ElasticSearch:在搜索结果中包含内部对象 - ElasticSearch: Include inner object in search result Elasticsearch:从点击中学习(搜索结果排名) - Elasticsearch: Learning from clicks (Search result ranking) Elasticsearch全局搜索多个索引上的不同过滤器 - Elasticsearch global search different filter on multiple indexes 有没有一种方法可以通过关键字和属性使elasticsearch(5.5)自动完成搜索? - Is there a way to make elasticsearch(5.5) autocomplete search by keyword and attribute? 如何使用php中的下拉列表过滤搜索结果 - how to filter search result with dropdown list in php springboot:修改query搜索mongo或者过滤结果 - Springboot: Modify query search Mongo or filter the result 如何获得给定关键字的搜索结果(以html格式)并在Talend中的所有搜索结果页面进行迭代? - How can I get the search result (in html) for a given keyword and iterate it for all search result pages in Talend? ElasticSearch索引字符串为整数,然后在搜索结果中获取整数值 - ElasticSearch indexing string as integer then getting back the integer value in search result
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM