# UnitTesting with Elasticsearch and issue with embedded elastic search node

**URL:** <https://discuss.elastic.co/t/unittesting-with-elasticsearch-and-issue-with-embedded-elastic-search-node/16521>\
**Category:** Elasticsearch\
**Created:** [March 21, 2014, 12:26pm UTC](https://discuss.elastic.co/t/unittesting-with-elasticsearch-and-issue-with-embedded-elastic-search-node/16521 "2014-03-21T12:26:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ramdev\_Wudali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramdev_wudali/32/7894_2.png) [@Ramdev\_Wudali](https://discuss.elastic.co/u/Ramdev_Wudali)\
**Post date:** [March 21, 2014, 12:26pm UTC](https://discuss.elastic.co/t/unittesting-with-elasticsearch-and-issue-with-embedded-elastic-search-node/16521/1 "2014-03-21T12:26:20Z")

</div>

Hi All:  
I have been trying to write a unitTest that tests some indexing and  
search functionality against an embedded instance of Elasticsearch so  
that I do not have to rely on a test instance of Elasticsearch being  
available. Towards this goal, I create a local node instance like so :

```
    ImmutableSettings.Builder elasticsearchSettings =

```

> ```
> ImmutableSettings.settingsBuilder()
> 
> .put("http.enabled",false)
> 
> .put("path.data",dataDirectory);
> 
> ```
> 
> > ```
> > node = 
> > 
> > ```
> > 
> > nodeBuilder().local(true).settings(elasticsearchSettings.build()).node();

and I get get a client instance like so :

Client client = node.client();

So far so good. I proceed to index a single document like so :

```
    client.prepareIndex("testindex", "testDocument", 

```

> > testDocument.getDocumentId())
> 
> > .setSource(jsonStringnormalized).execute().actionGet();
> 
> where jsonStringnormalized is the JSON representation of the testDocument  
> and testDocument.getDocumnetId() returns the ID for the document.

I then perform two requests, 1 a Get request (using GetReponse) and the  
second a SearchResponse.  
The GetReponse returns the document I just indexed. However my search  
request (where is a query :QueryBuilders.matchAllQuery() ) returns no  
documents.

My Question is this, What is the difference between the GetReponse request  
and a SearchResposne request.  
Is there a way for the SearchResponse to succeed in this environment

Thanks much

Ramdev

--  
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/695422a4-0f8f-4877-9bfd-feb56292ab90%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/695422a4-0f8f-4877-9bfd-feb56292ab90%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ramdev\_Wudali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ramdev_wudali/32/7894_2.png) [@Ramdev\_Wudali](https://discuss.elastic.co/u/Ramdev_Wudali)\
**Post date:** [March 21, 2014, 12:37pm UTC](https://discuss.elastic.co/t/unittesting-with-elasticsearch-and-issue-with-embedded-elastic-search-node/16521/2 "2014-03-21T12:37:31Z")

</div>

The get response is like so :

```
    GetResponse gr = client.prepareGet("testindex", "testDocument", 

```

> testDocument.getDocumentId()).execute().actionGet();

The searchResponse is like so :

```
    SearchResponse sr = 

```

> > client.prepareSearch("testindex").setTypes("testDocument")
> 
> > .setSearchType(SearchType.QUERY\_AND\_FETCH).setQuery(QueryBuilders.matchAllQuery())
> 
> ```
> .setExplain(true).execute().actionGet();
> 
> ```

is there a commit like function call after index that is preventing the  
index from being created ? (like a flush ?)

Thanks

Ramdev

On Friday, 21 March 2014 07:26:20 UTC-5, Ramdev Wudali wrote:

> Hi All:  
> I have been trying to write a unitTest that tests some indexing and  
> search functionality against an embedded instance of Elasticsearch so  
> that I do not have to rely on a test instance of Elasticsearch being  
> available. Towards this goal, I create a local node instance like so :
> 
> ```
> ImmutableSettings.Builder elasticsearchSettings =
> 
> ```
> 
> > ```
> > ImmutableSettings.settingsBuilder()
> > 
> > .put("http.enabled",false)
> > 
> > .put("path.data",dataDirectory);
> > 
> > ```
> > 
> > > ```
> > > node = 
> > > 
> > > ```
> > > 
> > > nodeBuilder().local(true).settings(elasticsearchSettings.build()).node();
> 
> and I get get a client instance like so :
> 
> Client client = node.client();
> 
> So far so good. I proceed to index a single document like so :
> 
> ```
> client.prepareIndex("testindex", "testDocument", 
> 
> ```
> 
> > > testDocument.getDocumentId())
> > 
> > > .setSource(jsonStringnormalized).execute().actionGet();
> > 
> > where jsonStringnormalized is the JSON representation of the  
> > testDocument and testDocument.getDocumnetId() returns the ID for the  
> > document.
> 
> I then perform two requests, 1 a Get request (using GetReponse) and the  
> second a SearchResponse.  
> The GetReponse returns the document I just indexed. However my search  
> request (where is a query :QueryBuilders.matchAllQuery() ) returns no  
> documents.
> 
> My Question is this, What is the difference between the GetReponse request  
> and a SearchResposne request.  
> Is there a way for the SearchResponse to succeed in this environment
> 
> Thanks much
> 
> Ramdev

--  
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/bff8712e-482c-4d0b-a51a-81ffc43597e8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/bff8712e-482c-4d0b-a51a-81ffc43597e8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Henrik\_Nordvik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/henrik_nordvik/32/1096_2.png) [@Henrik\_Nordvik](https://discuss.elastic.co/u/Henrik_Nordvik)\
**Post date:** [March 22, 2014, 1:50pm UTC](https://discuss.elastic.co/t/unittesting-with-elasticsearch-and-issue-with-embedded-elastic-search-node/16521/3 "2014-03-22T13:50:04Z")

</div>

The update of the search indexes happens asynchronously (normally after  
about 1s), but in testing you can force a refresh on the index before  
issuing the search request.  
i.e.:  
client().admin().indices().prepareRefresh("testindex").execute().get()

or you can use setRefresh(true) on the indexing request.

- 

Henrik

On Friday, March 21, 2014 1:26:20 PM UTC+1, Ramdev Wudali wrote:

> Hi All:  
> I have been trying to write a unitTest that tests some indexing and  
> search functionality against an embedded instance of Elasticsearch so  
> that I do not have to rely on a test instance of Elasticsearch being  
> available. Towards this goal, I create a local node instance like so :
> 
> ```
> ImmutableSettings.Builder elasticsearchSettings =
> 
> ```
> 
> > ```
> > ImmutableSettings.settingsBuilder()
> > 
> > .put("http.enabled",false)
> > 
> > .put("path.data",dataDirectory);
> > 
> > ```
> > 
> > > ```
> > > node = 
> > > 
> > > ```
> > > 
> > > nodeBuilder().local(true).settings(elasticsearchSettings.build()).node();
> 
> and I get get a client instance like so :
> 
> Client client = node.client();
> 
> So far so good. I proceed to index a single document like so :
> 
> ```
> client.prepareIndex("testindex", "testDocument", 
> 
> ```
> 
> > > testDocument.getDocumentId())
> > 
> > > .setSource(jsonStringnormalized).execute().actionGet();
> > 
> > where jsonStringnormalized is the JSON representation of the  
> > testDocument and testDocument.getDocumnetId() returns the ID for the  
> > document.
> 
> I then perform two requests, 1 a Get request (using GetReponse) and the  
> second a SearchResponse.  
> The GetReponse returns the document I just indexed. However my search  
> request (where is a query :QueryBuilders.matchAllQuery() ) returns no  
> documents.
> 
> My Question is this, What is the difference between the GetReponse request  
> and a SearchResposne request.  
> Is there a way for the SearchResponse to succeed in this environment
> 
> Thanks much
> 
> Ramdev

--  
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/70d83c09-bde5-4a55-9bf9-2328c917f239%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/70d83c09-bde5-4a55-9bf9-2328c917f239%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, 1:41am UTC](https://discuss.elastic.co/t/unittesting-with-elasticsearch-and-issue-with-embedded-elastic-search-node/16521/4 "2017-07-06T01:41:22Z")

</div>


