gpt4 book ai didi

java - 我有多个 Elasticsearch 的应该案例,但只有第一个有效

转载 作者:行者123 更新时间:2023-12-01 17:43:25 25 4
gpt4 key购买 nike

我已经分享了出现错误的脚本。它只匹配第一个应该情况,而不匹配其余的情况

 BoolQueryBuilder boolqueryBuilder = new BoolQueryBuilder();
boolqueryBuilder
.should(QueryBuilders.matchPhrasePrefixQuery("dishName", (userSearchCriteriaContainer.getSearchString() == null ? "" : userSearchCriteriaContainer.getSearchString())))
.should(QueryBuilders.termQuery("cuisineTypes", String.valueOf(userSearchCriteriaContainer.getCuisineTypes())) )
.should(QueryBuilders.termQuery("mealType", String.valueOf(userSearchCriteriaContainer.getDishList())) )
.should(QueryBuilders.termQuery("preparationTime", String.valueOf(userSearchCriteriaContainer.getPreparationTime())) );

SearchRequest searchRequest = config.client().prepareSearch("dishes").setQuery(boolqueryBuilder).setExplain(true).setFrom(0).setSize(100).request();

org.elasticsearch.action.search.SearchResponse response = null;
try {
response = config.restClient().search(searchRequest, RequestOptions.DEFAULT);
} catch (IOException e) {

e.printStackTrace();
}

最佳答案

当没有“必须”时,“应该”必须符合条件。

可以将其添加到后面(.minimumShouldMatch(2))

至少两个条件。

boolqueryBuilder
.should(QueryBuilders.matchPhrasePrefixQuery("dishName", (userSearchCriteriaContainer.getSearchString() == null ? "" : userSearchCriteriaContainer.getSearchString())))
.should(QueryBuilders.termQuery("cuisineTypes", String.valueOf(userSearchCriteriaContainer.getCuisineTypes())) )
.should(QueryBuilders.termQuery("mealType", String.valueOf(userSearchCriteriaContainer.getDishList())) )
.should(QueryBuilders.termQuery("preparationTime", String.valueOf(userSearchCriteriaContainer.getPreparationTime())) )
.minimumShouldMatch(2);

关于java - 我有多个 Elasticsearch 的应该案例,但只有第一个有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60906551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com