# Unit/integration testing elastic search instance

**URL:** <https://discuss.elastic.co/t/unit-integration-testing-elastic-search-instance/3025>\
**Category:** Elasticsearch\
**Created:** [June 17, 2010, 4:27pm UTC](https://discuss.elastic.co/t/unit-integration-testing-elastic-search-instance/3025 "2010-06-17T16:27:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwkohout](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mwkohout/32/49570_2.png) [@mwkohout](https://discuss.elastic.co/u/mwkohout)\
**Post date:** [June 17, 2010, 4:27pm UTC](https://discuss.elastic.co/t/unit-integration-testing-elastic-search-instance/3025/1 "2010-06-17T16:27:28Z")

</div>

Hi all;

I'm a new user who's integrated elastic search into a grails application.  
Now, I'd like to write some tests. To test the service, I was looking for  
a way to synchronously rebuild my indices, rather than send an asynchronous  
request(that way I can get consistent behavior).

Does elastic search provide anything like this? If so, what does this call  
on a elastic search node or client look like?

thanks  
Mike Kohout

---

<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 17, 2010, 6:54pm UTC](https://discuss.elastic.co/t/unit-integration-testing-elastic-search-instance/3025/2 "2010-06-17T18:54:02Z")

</div>

In order to test elasticsearch in this scenario, I would suggest starting  
elasticsearch in local mode (local to the JVM using the node builder) within  
your test. I am not sure what you mean regarding the async index requests,  
do you mean that you call index but don't call "get" on the result? Or is it  
the near real time aspect of elasticsearch? If its the latter, you can call  
the refresh API in your tests to see the latest changes done in your tests.

-shay.banon

On Thu, Jun 17, 2010 at 7:27 PM, Michael Kohout [mwkohout@gmail.com](mailto:mwkohout@gmail.com) wrote:

> Hi all;
> 
> I'm a new user who's integrated Elasticsearch into a grails application.  
> Now, I'd like to write some tests. To test the service, I was looking for  
> a way to synchronously rebuild my indices, rather than send an asynchronous  
> request(that way I can get consistent behavior).
> 
> Does Elasticsearch provide anything like this? If so, what does this call  
> on a Elasticsearch node or client look like?
> 
> thanks  
> Mike Kohout

---

<div class="post-metadata">

**Author:** ![mwkohout](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mwkohout/32/49570_2.png) [@mwkohout](https://discuss.elastic.co/u/mwkohout)\
**Post date:** [June 17, 2010, 9:01pm UTC](https://discuss.elastic.co/t/unit-integration-testing-elastic-search-instance/3025/3 "2010-06-17T21:01:18Z")

</div>

Yup, I've already got it running inside the webapp jvm. I think the problem  
is the "near real time" aspect of Elasticsearch but I'm just guessing.

What I'm thinking I've got to do, is replace this():  
def builder =  
node.client.admin.indices.indicesAdminClient.prepareRefresh("project")

node.client.admin.indices.indicesAdminClient.refresh(builder.request)  
which exists inside a method that will index a passed in domain object(the  
method is included at the end of my message) with...something that will work  
in a synchronous manner.

What do you think? Does my conclusion make sense?  
Mike

def index(Project p) {  
def indexR = node.client.index {  
index "project"  
type "project"  
id p.id  
source {  
name = p.name  
username = p.user.username  
tags = p.tags

```
        }
    }
    indexR.failure = {Throwable t ->
        println "couldn't index ${p}"
    }
    indexR.success = {IndexResponse response ->
        println "here"
    }
    def builder =

```

node.client.admin.indices.indicesAdminClient.prepareRefresh("project")

node.client.admin.indices.indicesAdminClient.refresh(builder.request)  
}

On Thu, Jun 17, 2010 at 1:54 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> In order to test elasticsearch in this scenario, I would suggest starting  
> elasticsearch in local mode (local to the JVM using the node builder) within  
> your test. I am not sure what you mean regarding the async index requests,  
> do you mean that you call index but don't call "get" on the result? Or is it  
> the near real time aspect of elasticsearch? If its the latter, you can call  
> the refresh API in your tests to see the latest changes done in your tests.
> 
> -shay.banon
> 
> On Thu, Jun 17, 2010 at 7:27 PM, Michael Kohout [mwkohout@gmail.com](mailto:mwkohout@gmail.com)wrote:
> 
> > Hi all;
> > 
> > I'm a new user who's integrated Elasticsearch into a grails application.  
> > Now, I'd like to write some tests. To test the service, I was looking for  
> > a way to synchronously rebuild my indices, rather than send an asynchronous  
> > request(that way I can get consistent behavior).
> > 
> > Does Elasticsearch provide anything like this? If so, what does this  
> > call on a Elasticsearch node or client look like?
> > 
> > thanks  
> > Mike Kohout

---

<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 17, 2010, 9:40pm UTC](https://discuss.elastic.co/t/unit-integration-testing-elastic-search-instance/3025/4 "2010-06-17T21:40:45Z")

</div>

Yes, it make sense, but only do it when testings, refreshing on every index  
request in production is very expensive. By the way, I plan to enable the  
"prepare" API as groovy extended APIs.

-shay.banon

On Fri, Jun 18, 2010 at 12:01 AM, Michael Kohout [mwkohout@gmail.com](mailto:mwkohout@gmail.com) wrote:

> Yup, I've already got it running inside the webapp jvm. I think the  
> problem is the "near real time" aspect of Elasticsearch but I'm just  
> guessing.
> 
> What I'm thinking I've got to do, is replace this():  
> def builder =  
> node.client.admin.indices.indicesAdminClient.prepareRefresh("project")
> 
> node.client.admin.indices.indicesAdminClient.refresh(builder.request)  
> which exists inside a method that will index a passed in domain object(the  
> method is included at the end of my message) with...something that will work  
> in a synchronous manner.
> 
> What do you think? Does my conclusion make sense?  
> Mike
> 
> def index(Project p) {  
> def indexR = node.client.index {  
> index "project"  
> type "project"  
> id p.id  
> source {  
> name = p.name  
> username = p.user.username  
> tags = p.tags
> 
> ```
> }
> }
> indexR.failure = {Throwable t ->
> println "couldn't index ${p}"
> }
> indexR.success = {IndexResponse response ->
> println "here"
> }
> def builder =
> 
> ```
> 
> node.client.admin.indices.indicesAdminClient.prepareRefresh("project")
> 
> node.client.admin.indices.indicesAdminClient.refresh(builder.request)  
> }
> 
> On Thu, Jun 17, 2010 at 1:54 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > In order to test elasticsearch in this scenario, I would suggest starting  
> > elasticsearch in local mode (local to the JVM using the node builder) within  
> > your test. I am not sure what you mean regarding the async index requests,  
> > do you mean that you call index but don't call "get" on the result? Or is it  
> > the near real time aspect of elasticsearch? If its the latter, you can call  
> > the refresh API in your tests to see the latest changes done in your tests.
> > 
> > -shay.banon
> > 
> > On Thu, Jun 17, 2010 at 7:27 PM, Michael Kohout [mwkohout@gmail.com](mailto:mwkohout@gmail.com)wrote:
> > 
> > > Hi all;
> > > 
> > > I'm a new user who's integrated Elasticsearch into a grails application.  
> > > Now, I'd like to write some tests. To test the service, I was looking for  
> > > a way to synchronously rebuild my indices, rather than send an asynchronous  
> > > request(that way I can get consistent behavior).
> > > 
> > > Does Elasticsearch provide anything like this? If so, what does this  
> > > call on a Elasticsearch node or client look like?
> > > 
> > > thanks  
> > > Mike Kohout

---

<div class="post-metadata">

**Author:** ![mwkohout](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mwkohout/32/49570_2.png) [@mwkohout](https://discuss.elastic.co/u/mwkohout)\
**Post date:** [June 18, 2010, 4:43pm UTC](https://discuss.elastic.co/t/unit-integration-testing-elastic-search-instance/3025/5 "2010-06-18T16:43:56Z")

</div>

Fantastic! Thanks for your help. I feel a bit foolish asking, but could  
you point me towards the url documenting the java or rest api calls that  
I've got to do to get a synchronous index refresh?

thanks  
Mike  
On Thu, Jun 17, 2010 at 4:40 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Yes, it make sense, but only do it when testings, refreshing on every index  
> request in production is very expensive. By the way, I plan to enable the  
> "prepare" API as groovy extended APIs.
> 
> -shay.banon
> 
> On Fri, Jun 18, 2010 at 12:01 AM, Michael Kohout [mwkohout@gmail.com](mailto:mwkohout@gmail.com)wrote:
> 
> > Yup, I've already got it running inside the webapp jvm. I think the  
> > problem is the "near real time" aspect of Elasticsearch but I'm just  
> > guessing.
> > 
> > What I'm thinking I've got to do, is replace this():  
> > def builder =  
> > node.client.admin.indices.indicesAdminClient.prepareRefresh("project")
> > 
> > node.client.admin.indices.indicesAdminClient.refresh(builder.request)  
> > which exists inside a method that will index a passed in domain object(the  
> > method is included at the end of my message) with...something that will work  
> > in a synchronous manner.
> > 
> > What do you think? Does my conclusion make sense?  
> > Mike
> > 
> > def index(Project p) {  
> > def indexR = node.client.index {  
> > index "project"  
> > type "project"  
> > id p.id  
> > source {  
> > name = p.name  
> > username = p.user.username  
> > tags = p.tags
> > 
> > ```
> > }
> > }
> > indexR.failure = {Throwable t ->
> > println "couldn't index ${p}"
> > }
> > indexR.success = {IndexResponse response ->
> > println "here"
> > }
> > def builder =
> > 
> > ```
> > 
> > node.client.admin.indices.indicesAdminClient.prepareRefresh("project")
> > 
> > node.client.admin.indices.indicesAdminClient.refresh(builder.request)  
> > }
> > 
> > On Thu, Jun 17, 2010 at 1:54 PM, Shay Banon \<[shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)
> > 
> > > wrote:
> > 
> > > In order to test elasticsearch in this scenario, I would suggest starting  
> > > elasticsearch in local mode (local to the JVM using the node builder) within  
> > > your test. I am not sure what you mean regarding the async index requests,  
> > > do you mean that you call index but don't call "get" on the result? Or is it  
> > > the near real time aspect of elasticsearch? If its the latter, you can call  
> > > the refresh API in your tests to see the latest changes done in your tests.
> > > 
> > > -shay.banon
> > > 
> > > On Thu, Jun 17, 2010 at 7:27 PM, Michael Kohout [mwkohout@gmail.com](mailto:mwkohout@gmail.com)wrote:
> > > 
> > > > Hi all;
> > > > 
> > > > I'm a new user who's integrated Elasticsearch into a grails  
> > > > application. Now, I'd like to write some tests. To test the service, I was  
> > > > looking for a way to synchronously rebuild my indices, rather than send an  
> > > > asynchronous request(that way I can get consistent behavior).
> > > > 
> > > > Does Elasticsearch provide anything like this? If so, what does this  
> > > > call on a Elasticsearch node or client look like?
> > > > 
> > > > thanks  
> > > > Mike Kohout

---

<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 19, 2010, 9:31pm UTC](https://discuss.elastic.co/t/unit-integration-testing-elastic-search-instance/3025/6 "2010-06-19T21:31:48Z")

</div>

Here is the call from the groovy tests I have:

```
    def refresh = node.client.admin.indices.refresh {}
    assertThat refresh.response.failedShards, equalTo(0)

```

-shay.banon

On Fri, Jun 18, 2010 at 7:43 PM, Michael Kohout [mwkohout@gmail.com](mailto:mwkohout@gmail.com) wrote:

> Fantastic! Thanks for your help. I feel a bit foolish asking, but could  
> you point me towards the url documenting the java or rest api calls that  
> I've got to do to get a synchronous index refresh?
> 
> thanks  
> Mike
> 
> On Thu, Jun 17, 2010 at 4:40 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:
> 
> > Yes, it make sense, but only do it when testings, refreshing on every  
> > index request in production is very expensive. By the way, I plan to enable  
> > the "prepare" API as groovy extended APIs.
> > 
> > -shay.banon
> > 
> > On Fri, Jun 18, 2010 at 12:01 AM, Michael Kohout [mwkohout@gmail.com](mailto:mwkohout@gmail.com)wrote:
> > 
> > > Yup, I've already got it running inside the webapp jvm. I think the  
> > > problem is the "near real time" aspect of Elasticsearch but I'm just  
> > > guessing.
> > > 
> > > What I'm thinking I've got to do, is replace this():  
> > > def builder =  
> > > node.client.admin.indices.indicesAdminClient.prepareRefresh("project")
> > > 
> > > node.client.admin.indices.indicesAdminClient.refresh(builder.request)  
> > > which exists inside a method that will index a passed in domain  
> > > object(the method is included at the end of my message) with...something  
> > > that will work in a synchronous manner.
> > > 
> > > What do you think? Does my conclusion make sense?  
> > > Mike
> > > 
> > > def index(Project p) {  
> > > def indexR = node.client.index {  
> > > index "project"  
> > > type "project"  
> > > id p.id  
> > > source {  
> > > name = p.name  
> > > username = p.user.username  
> > > tags = p.tags
> > > 
> > > ```
> > > }
> > > }
> > > indexR.failure = {Throwable t ->
> > > println "couldn't index ${p}"
> > > }
> > > indexR.success = {IndexResponse response ->
> > > println "here"
> > > }
> > > def builder =
> > > 
> > > ```
> > > 
> > > node.client.admin.indices.indicesAdminClient.prepareRefresh("project")
> > > 
> > > node.client.admin.indices.indicesAdminClient.refresh(builder.request)  
> > > }
> > > 
> > > On Thu, Jun 17, 2010 at 1:54 PM, Shay Banon \<  
> > > [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)\> wrote:
> > > 
> > > > In order to test elasticsearch in this scenario, I would suggest  
> > > > starting elasticsearch in local mode (local to the JVM using the node  
> > > > builder) within your test. I am not sure what you mean regarding the async  
> > > > index requests, do you mean that you call index but don't call "get" on the  
> > > > result? Or is it the near real time aspect of elasticsearch? If its the  
> > > > latter, you can call the refresh API in your tests to see the latest changes  
> > > > done in your tests.
> > > > 
> > > > -shay.banon
> > > > 
> > > > On Thu, Jun 17, 2010 at 7:27 PM, Michael Kohout [mwkohout@gmail.com](mailto:mwkohout@gmail.com)wrote:
> > > > 
> > > > > Hi all;
> > > > > 
> > > > > I'm a new user who's integrated Elasticsearch into a grails  
> > > > > application. Now, I'd like to write some tests. To test the service, I was  
> > > > > looking for a way to synchronously rebuild my indices, rather than send an  
> > > > > asynchronous request(that way I can get consistent behavior).
> > > > > 
> > > > > Does Elasticsearch provide anything like this? If so, what does this  
> > > > > call on a Elasticsearch node or client look like?
> > > > > 
> > > > > thanks  
> > > > > Mike Kohout

---

<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:23am UTC](https://discuss.elastic.co/t/unit-integration-testing-elastic-search-instance/3025/7 "2017-07-06T04:23:12Z")

</div>


