Add null check (#20518)

This commit is contained in:
Mohit Yadav 2025-03-31 23:44:20 +05:30 committed by GitHub
parent c550ca0112
commit 7a49a94235
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View File

@ -2366,8 +2366,12 @@ public class ElasticSearchClient implements SearchClient {
.createParser(
EsUtils.esXContentRegistry, LoggingDeprecationHandler.INSTANCE, queryFilter);
QueryBuilder filter = SearchSourceBuilder.fromXContent(filterParser).query();
BoolQueryBuilder newQuery =
QueryBuilders.boolQuery().must(searchSourceBuilder.query()).filter(filter);
BoolQueryBuilder newQuery;
if (!nullOrEmpty(searchSourceBuilder.query())) {
newQuery = QueryBuilders.boolQuery().must(searchSourceBuilder.query()).filter(filter);
} else {
newQuery = QueryBuilders.boolQuery().filter(filter);
}
searchSourceBuilder.query(newQuery);
} catch (Exception ex) {
LOG.warn("Error parsing query_filter from query parameters, ignoring filter", ex);

View File

@ -2457,8 +2457,12 @@ public class OpenSearchClient implements SearchClient {
.createParser(
OsUtils.osXContentRegistry, LoggingDeprecationHandler.INSTANCE, queryFilter);
QueryBuilder filter = SearchSourceBuilder.fromXContent(filterParser).query();
BoolQueryBuilder newQuery =
QueryBuilders.boolQuery().must(searchSourceBuilder.query()).filter(filter);
BoolQueryBuilder newQuery;
if (!nullOrEmpty(searchSourceBuilder.query())) {
newQuery = QueryBuilders.boolQuery().must(searchSourceBuilder.query()).filter(filter);
} else {
newQuery = QueryBuilders.boolQuery().filter(filter);
}
searchSourceBuilder.query(newQuery);
} catch (Exception ex) {
LOG.warn("Error parsing query_filter from query parameters, ignoring filter", ex);