# Rest and RestHighLevelClient query differences

**URL:** <https://discuss.elastic.co/t/rest-and-resthighlevelclient-query-differences/143557>\
**Category:** Elasticsearch\
**Created:** [August 8, 2018, 3:35pm UTC](https://discuss.elastic.co/t/rest-and-resthighlevelclient-query-differences/143557 "2018-08-08T15:35:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![katre](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@katre](https://discuss.elastic.co/u/katre)\
**Post date:** [August 8, 2018, 3:35pm UTC](https://discuss.elastic.co/t/rest-and-resthighlevelclient-query-differences/143557/1 "2018-08-08T15:35:29Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [August 10, 2018, 9:11am UTC](https://discuss.elastic.co/t/rest-and-resthighlevelclient-query-differences/143557/2 "2018-08-10T09:11:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![katre](https://avatars.discourse-cdn.com/v4/letter/k/f6c823/32.png) [@katre](https://discuss.elastic.co/u/katre)\
**Post date:** [August 10, 2018, 10:13am UTC](https://discuss.elastic.co/t/rest-and-resthighlevelclient-query-differences/143557/3 "2018-08-10T10:13:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [August 10, 2018, 10:26am UTC](https://discuss.elastic.co/t/rest-and-resthighlevelclient-query-differences/143557/4 "2018-08-10T10:26:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 7, 2018, 10:26am UTC](https://discuss.elastic.co/t/rest-and-resthighlevelclient-query-differences/143557/5 "2018-09-07T10:26:56Z")

</div>

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