# Range query in unit test

**URL:** <https://discuss.elastic.co/t/range-query-in-unit-test/4571>\
**Category:** Elasticsearch\
**Created:** [June 8, 2011, 9:28am UTC](https://discuss.elastic.co/t/range-query-in-unit-test/4571 "2011-06-08T09:28:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Treff7es](https://avatars.discourse-cdn.com/v4/letter/t/9fc348/32.png) [@Treff7es](https://discuss.elastic.co/u/Treff7es)\
**Post date:** [June 8, 2011, 9:28am UTC](https://discuss.elastic.co/t/range-query-in-unit-test/4571/1 "2011-06-08T09:28:07Z")

</div>

Hi,

I've just started to play with elasticsearch and I wanted to write  
basic java unit tests for testing the core functionality of  
elasticsearch.  
I created a local node with nodebuilder  
(nodeBuilder().local(true).settings(settings).node()) for my unit  
tests and inserted some test data into it and I wanted to test the  
query functionalities, how it is work.  
At every insert function I set the refresh(true) property and most of  
the queries worked fine from unit test (query for field, wildcard  
queries, etc...) right after the insertion.  
However when I searched with a queryString which contained a  
rangeQuery (for date) then it most of the times returned with empty  
resultset and sometimes it returned with the correct resultset.  
When I started to play with the different settings then I found out,  
if I force elasticsearch to flush data then rangeQuery always gave me  
back the correct resultset.

I'm wondering why this happened and why just range queries were  
affected.  
Can anybody explain me, why this happened?

Thanks,  
Tamas

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 8, 2011, 9:31am UTC](https://discuss.elastic.co/t/range-query-in-unit-test/4571/2 "2011-06-08T09:31:12Z")

</div>

Can you gist your sample code?

On Wednesday, June 8, 2011 at 12:28 PM, Tamás wrote:

> Hi,
> 
> I've just started to play with elasticsearch and I wanted to write  
> basic java unit tests for testing the core functionality of  
> elasticsearch.  
> I created a local node with nodebuilder  
> (nodeBuilder().local(true).settings(settings).node()) for my unit  
> tests and inserted some test data into it and I wanted to test the  
> query functionalities, how it is work.  
> At every insert function I set the refresh(true) property and most of  
> the queries worked fine from unit test (query for field, wildcard  
> queries, etc...) right after the insertion.  
> However when I searched with a queryString which contained a  
> rangeQuery (for date) then it most of the times returned with empty  
> resultset and sometimes it returned with the correct resultset.  
> When I started to play with the different settings then I found out,  
> if I force elasticsearch to flush data then rangeQuery always gave me  
> back the correct resultset.
> 
> I'm wondering why this happened and why just range queries were  
> affected.  
> Can anybody explain me, why this happened?
> 
> Thanks,  
> Tamas

---

<div class="post-metadata">

**Author:** ![fashionalwallet](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fashionalwallet](https://discuss.elastic.co/u/fashionalwallet)\
**Post date:** [June 9, 2011, 9:13am UTC](https://discuss.elastic.co/t/range-query-in-unit-test/4571/3 "2011-06-09T09:13:03Z")

</div>

- deleted -

---

<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:** [July 6, 2017, 4:04am UTC](https://discuss.elastic.co/t/range-query-in-unit-test/4571/4 "2017-07-06T04:04:19Z")

</div>

Closed on July 6, 2017, 4:04am UTC


