Migration of elasticsearch java Client from 1.4.2 to 7.2 (problem in filteredQuery method)


Currently i am running elasticsearch in 1.4.2 and I trying to make it run in 7.2 , the problem that i found is in The method filteredQuery(MatchAllQueryBuilder, String, String) and filteredQuery(MatchAllQueryBuilder, QueryBuilder[]), i didn't found any alternative methode knowing that they are deprecated, but for this implementation of filteredQuery : filteredQuery(QueryBuilder,QueryBuilder) i found that i should use boolquery() with filter clause.

Please, If there's any suggestion, do not hesitate.
Thank You !

(https://static.javadoc.io/org.elasticsearch/elasticsearch/2.4.0/org/elasticsearch/index/query/QueryBuilder.html) filterBuilder)

I think you should give this forum a chance before asking in another place.

i found that i should use boolquery() with filter clause.

Yes you need to use boolQuery() instead.

1 Like

well, boolquery is for filteredQuery(QueryBuilder,QueryBuilder) , but for filteredQuery(MatchAllQueryBuilder, String, String) and filteredQuery(MatchAllQueryBuilder, QueryBuilder[]) I don't think it match the boolquery() implementation, can you give an example of how i should use boolquery for these two case of filteredQuery ?

Thank You !

Could you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Then based on this Kibana script we can find what would be the Java code.

private QueryBuilder queryBuilder() {
	QueryBuilder fb = queryCatBuilder();
	BoolQueryBuilder builder = QueryBuilders.boolQuery();
	if(request.getContent() == null || "".equals(request.getContent())){
		if(fb == null)
			return QueryBuilders.matchAllQuery();

		return builder;
	if(fb == null)
		return QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), FIELD_ALL, 
	return QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),

see the returns statement.

Please provide a Kibana script that we can run in Kibana dev console.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.