Unit/integration testing elastic search instance


(mwkohout) #1

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


(Shay Banon) #2

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 wrote:

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


(mwkohout) #3

Yup, I've already got it running inside the webapp jvm. I think the problem
is the "near real time" aspect of elastic search 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.comwrote:

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.comwrote:

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


(Shay Banon) #4

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 wrote:

Yup, I've already got it running inside the webapp jvm. I think the
problem is the "near real time" aspect of elastic search 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.comwrote:

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.comwrote:

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


(mwkohout) #5

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.comwrote:

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.comwrote:

Yup, I've already got it running inside the webapp jvm. I think the
problem is the "near real time" aspect of elastic search 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

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.comwrote:

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


(Shay Banon) #6

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 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.comwrote:

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.comwrote:

Yup, I've already got it running inside the webapp jvm. I think the
problem is the "near real time" aspect of elastic search 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> 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.comwrote:

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


(system) #7