This query gives me expected results when run using a simple GET request on ES.
Problem:
I want to translate the query using Java API client and here's what I tried to do:
BoolQuery.Builder queryBuilder = new BoolQuery.Builder();
FieldValue value = FieldValue.of("chair");
Query byName = MatchQuery.of(m -> m
.field("detected.tag")
.query(value)
)._toQuery();
queryBuilder.must(byName);
SearchRequest.Builder searchRequestBuilder = new SearchRequest.Builder();
searchRequestBuilder.query(queryBuilder.build()._toQuery());
// Execute query
ElasticSearch es = new ElasticSearch();
SearchResponse<Object> results = es.search(searchRequestBuilder);
return JsonpUtils.toJsonString(results, new JacksonJsonpMapper());
{"query":{"bool":{"must":[{"match":{"detected.tag":{"query":"chair"}}}]}}}
ES client keeps adding this word "query" to the generated query and hence I do not get any results!
Can you please point out if I'm doing something wrong? Or is it a bug?
The problem is not "query" inside the match.
I see that you don't indicate what the index is in the SearchRequest, but that wouldn't be a problem if there is "detected.tag" = "chair" in any index.
What is this?
Should you pass the searchrequest and TDocument to the search?
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.