# ElasticsearchSingleNodeTest search issues

**URL:** <https://discuss.elastic.co/t/elasticsearchsinglenodetest-search-issues/23029>\
**Category:** Elasticsearch\
**Created:** [April 1, 2015, 8:10am UTC](https://discuss.elastic.co/t/elasticsearchsinglenodetest-search-issues/23029 "2015-04-01T08:10:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ariel](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@ariel](https://discuss.elastic.co/u/ariel)\
**Post date:** [April 1, 2015, 8:10am UTC](https://discuss.elastic.co/t/elasticsearchsinglenodetest-search-issues/23029/1 "2015-04-01T08:10:15Z")

</div>

I'm attempting to write unit test for my code which searches through a  
number of indexes and only returns documents which match a certain term.

The query i use is rather simple:

{  
"query":  
{  
"from" : 0,  
"size" : 20,  
"query" : {  
"term" : {  
"resource\_affectedID" : 206158433329  
}  
},  
"aggregations" : {  
"count" : {  
"value\_count" : {  
"field" : "resource\_affectedID"  
}  
}  
}  
}  
}

This works against a real cluster but when I run this query against a  
client from ElasticsearchSingleNodeTest I always get empty results.

My test cluster is being populated from real records. For the records i  
have an array of the \_source in entries.json they are inserted into the  
cluster with the following code:

String index = "audit-2015.01.01";  
createIndex(index);

File entriesFile = getResource("entries.json");

JSONParser jsonParser = new JSONParser();

JSONArray entries = (JSONArray) jsonParser.parse(new FileReader(entriesFile  
));

for (Object entry : entries) {  
IndexRequestBuilder builder = new IndexRequestBuilder(client());  
builder.setOpType(IndexRequest.OpType.CREATE);  
builder.setSource(entry.toString().getBytes());  
builder.setIndex(index);  
builder.setType("application\_logs");  
builder.setId(id.toString());

client().index(builder.request()).actionGet();  
id++;  
}

client().admin().indices().flush(new FlushRequest(index)).actionGet();

Any ideas why this works in a real cluster and not here?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 1, 2015, 8:25am UTC](https://discuss.elastic.co/t/elasticsearchsinglenodetest-search-issues/23029/2 "2015-04-01T08:25:39Z")

</div>

You need to run a refresh, not a flush.  
My 2 cents

--  
David Pilato - Developer | Evangelist

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co/)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 1 avr. 2015 à 10:10, [ariel@symphony.com](mailto:ariel@symphony.com) a écrit :
> 
> I'm attempting to write unit test for my code which searches through a number of indexes and only returns documents which match a certain term.
> 
> The query i use is rather simple:
> 
> {  
> "query":  
> {  
> "from" : 0,  
> "size" : 20,  
> "query" : {  
> "term" : {  
> "resource\_affectedID" : 206158433329  
> }  
> },  
> "aggregations" : {  
> "count" : {  
> "value\_count" : {  
> "field" : "resource\_affectedID"  
> }  
> }  
> }  
> }  
> }
> 
> This works against a real cluster but when I run this query against a client from ElasticsearchSingleNodeTest I always get empty results.
> 
> My test cluster is being populated from real records. For the records i have an array of the \_source in entries.json they are inserted into the cluster with the following code:
> 
> String index = "audit-2015.01.01";  
> createIndex(index);
> 
> File entriesFile = getResource("entries.json");
> 
> JSONParser jsonParser = new JSONParser();
> 
> JSONArray entries = (JSONArray) jsonParser.parse(new FileReader(entriesFile));
> 
> for (Object entry : entries) {  
> IndexRequestBuilder builder = new IndexRequestBuilder(client());  
> builder.setOpType(IndexRequest.OpType.CREATE);  
> builder.setSource(entry.toString().getBytes());  
> builder.setIndex(index);  
> builder.setType("application\_logs");  
> builder.setId(id.toString());
> 
> client().index(builder.request()).actionGet();  
> id++;  
> }
> 
> client().admin().indices().flush(new FlushRequest(index)).actionGet();
> 
> Any ideas why this works in a real cluster and not here?
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/6B3833A7-286B-4FD2-AFAE-B571F9690451%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/6B3833A7-286B-4FD2-AFAE-B571F9690451%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![ariel](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@ariel](https://discuss.elastic.co/u/ariel)\
**Post date:** [April 1, 2015, 8:41am UTC](https://discuss.elastic.co/t/elasticsearchsinglenodetest-search-issues/23029/3 "2015-04-01T08:41:19Z")

</div>

I tried added this line:

client().admin().indices().refresh(new RefreshRequest(index)).actionGet();

and that worked.

Thanks!

On Wednesday, April 1, 2015 at 1:25:55 AM UTC-7, David Pilato wrote:

> You need to run a refresh, not a flush.  
> My 2 cents
> 
> --  
> _David Pilato_ - Developer | Evangelist  
> _[elastic.co](http://elastic.co) [http://elastic.co](http://elastic.co)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs  
> [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 1 avr. 2015 à 10:10, [ar...@symphony.com](mailto:ar...@symphony.com) \<javascript:\> a écrit :
> 
> I'm attempting to write unit test for my code which searches through a  
> number of indexes and only returns documents which match a certain term.
> 
> The query i use is rather simple:
> 
> {  
> "query":  
> {  
> "from" : 0,  
> "size" : 20,  
> "query" : {  
> "term" : {  
> "resource\_affectedID" : 206158433329  
> }  
> },  
> "aggregations" : {  
> "count" : {  
> "value\_count" : {  
> "field" : "resource\_affectedID"  
> }  
> }  
> }  
> }  
> }
> 
> This works against a real cluster but when I run this query against a  
> client from ElasticsearchSingleNodeTest I always get empty results.
> 
> My test cluster is being populated from real records. For the records i  
> have an array of the \_source in entries.json they are inserted into the  
> cluster with the following code:
> 
> String index = "audit-2015.01.01";  
> createIndex(index);
> 
> File entriesFile = getResource("entries.json");
> 
> JSONParser jsonParser = new JSONParser();
> 
> JSONArray entries = (JSONArray) jsonParser.parse(new FileReader(  
> entriesFile));
> 
> for (Object entry : entries) {  
> IndexRequestBuilder builder = new IndexRequestBuilder(client());  
> builder.setOpType(IndexRequest.OpType.CREATE);  
> builder.setSource(entry.toString().getBytes());  
> builder.setIndex(index);  
> builder.setType("application\_logs");  
> builder.setId(id.toString());
> 
> client().index(builder.request()).actionGet();  
> id++;  
> }
> 
> client().admin().indices().flush(new FlushRequest(index)).actionGet();
> 
> Any ideas why this works in a real cluster and not here?
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c0782988-edd3-4e8d-9bed-ea0b755d5ce4%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4cc26945-5211-49e5-911e-02edbd74fb57%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4cc26945-5211-49e5-911e-02edbd74fb57%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:22am UTC](https://discuss.elastic.co/t/elasticsearchsinglenodetest-search-issues/23029/4 "2017-07-06T00:22:26Z")

</div>


