Rest and RestHighLevelClient query differences

Hi, I have a case where same query via java api returns 0 hits and in kibana dev tools returns document.

In java client:

SearchRequest{searchType=QUERY_THEN_FETCH, indices=[search-data], indicesOptions=IndicesOptions[id=38, ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, allow_aliases_to_multiple_indices=true, forbid_closed_indices=true, ignore_aliases=false], types=[], routing='null', preference='null', requestCache=null, scroll=Scroll{keepAlive=1m}, maxConcurrentShardRequests=0, batchedReduceSize=512, preFilterShardSize=128, allowPartialSearchResults=null, source={"from":0,"size":50,"query":{"bool":{"filter":[{"range":{"gameDate":{"from":"2018-08-07T15:50:30.782Z","to":"2018-08-07T15:52:30.782Z","include_lower":true,"include_upper":true,"format":"yyyy-MM-dd'T'HH:mm:ss.SSSZ","boost":1.0}}},{"match":{"gameType":{"query":"ro","operator":"OR","prefix_length":0,"max_expansions":50,"fuzzy_transpositions":true,"lenient":false,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"boost":1.0}}},{"bool":{"filter":[{"exists":{"field":"tagValue","boost":1.0}},{"match":{"tagValue":{"query":"tag3","operator":"OR","prefix_length":0,"max_expansions":50,"fuzzy_transpositions":true,"lenient":false,"zero_terms_query":"NONE","auto_generate_synonyms_phrase_query":true,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}}}}

Response:
{"_scroll_id":"...","took":0,"timed_out":false,"_shards":{"total":10,"successful":10,"skipped":0,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}

in kibana I simply paste the query part and get a result
GET /_search
{
"from": 0,
"size": 50,
"query": {
"bool": { ...

"hits": {
    "total": 1, ....

What am I missing here?

Can you post your java code and your json query please?

No matter, I 'fixed' tests by adding 1s delay between insert and read. Process of copying json from logs and pasting to kibana window was the magic since it took time. I'm afraid it will cause problems in prod so I suppose I will need to optimize indexing somehow.

You just need to call refresh in your test. or add the refresh wait_for parameter when indexing the document. Documents are not immediately available for search, there is an additional operation called refresh that makes them available to the search API. Refreshes happen automatically every second in Elasticsearch, which is why the 1 second wait solves the problem.

Cheers
Luca

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