UnitTesting with Elasticsearch and issue with embedded elastic search node

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/695422a4-0f8f-4877-9bfd-feb56292ab90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/bff8712e-482c-4d0b-a51a-81ffc43597e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/70d83c09-bde5-4a55-9bf9-2328c917f239%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.