HighLevelRest java client : Search query returning zero hits despite the equivalent HTTP curl call returning results (hits> 0)

I'm currently migrating all our elastic search client code (both in Java and python) to 6.2. The index and data creation works well but searches/queries on elastic search using the java client are now failing by either returning no results or not considering the filtering.

As example I'd like to write here the HTTP request done via command line (curl rest api) with the parameters obtained from debugging the code through the elastic search client:

 $> curl http://localhost:9200/cipher/_doc/_search?typed_keys=true&ignore_unavailable=false&expand_wildcards=open&allow_no_indices=true&search_type=query_then_fetch&batched_reduce_size=512  -H 'Content-Type: application/json' -d '{"from":0,"size":100,"query":{"bool":{"must":[{"query_string":{"query":"(title:abc abstractText:abc)","fields":[],"type":"best_fields","default_operator":"or","max_determinized_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"explain":false}'

The query above, run from the command line, returns a 200 OK response with lots of results in the body:

 {"took":129,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":58709253,"max_score":1.0,"hits":[{"_index":"cipher","_type":"_doc","_id":"1013609","_score":1.0, ....}

However when executing the request using the java client with the same parameters and body(source) the HttpResponse doesn't seem to have a body (entity is null) and I think that's why the result from the RestHighLevelClient is a response with zero hits, e.g.:


The code has changed to use a SearchRequest with SearchSourceBuilder (rather than SearchRequestBuilder) but the migration seems to be equivalent to me in terms of the data we provide to the es java client and in fact the curl above was constructed using the values evaluated from the debugger.

Any ideas why the entity response seems to be null or the response with zero hits?

Many thanks,

1 Like

Can you share your Java code which is calling the search method ?

May be you want to use the low level client instead if you want to pass the full json body instead of just the query part which is expected by the builder?

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