Converting IndexResponse to SearchResponse

Hi,

I am trying to use JSON builder to get some documents from elasticsearch db.

  IndexResponse response = client.prepareIndex("asset_index", "Asset"

).setSource(

      *jsonBuilder*().startObject().field("name", "FCC_SRV02"

).endObject()).execute().actionGet();

I am getting IndexResponse.

How can I convert IndexResponse to SearchResponse so I retrieve SearchHit[]

Regards,

Janusz

--

Hi Janusz,

Indexing is a different operation than searching.

So, after indexing a doc, you have to GET it or SEARCH it.

Have a look here:

https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex1/IndexTest.java#L69

https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L268
https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java

HTH
David.

Le 9 janvier 2013 à 10:56, JD jdalecki@tycoint.com a écrit :

Hi,

I am trying to use JSON builder to get some documents from elasticsearch db.

   IndexResponse response = client.prepareIndex("asset_index",

"Asset").setSource(

       jsonBuilder().startObject().field("name",

"FCC_SRV02").endObject()).execute().actionGet();

I am getting IndexResponse.

How can I convert IndexResponse to SearchResponse so I retrieve SearchHit

Regards,

Janusz

--

--
David Pilato
http://www.scrutmydocs.org/
http://dev.david.pilato.fr/
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

Sorry David. I feel a bit embarrassed by this question – you are obviously
right - I just did not click that this code is actually creating index and
not searching.

Thanks for the reply and clarification.

Regards,

janusz

On Wednesday, January 9, 2013 8:56:45 PM UTC+11, JD wrote:

Hi,

I am trying to use JSON builder to get some documents from elasticsearch
db.

  IndexResponse response = client.prepareIndex("asset_index", "Asset"

).setSource(

      *jsonBuilder*().startObject().field("name", "FCC_SRV02"

).endObject()).execute().actionGet();

I am getting IndexResponse.

How can I convert IndexResponse to SearchResponse so I retrieve *SearchHit

Regards,

Janusz

--

Just a new clarification about the terms you use.
This command does not create an index but index a document.

Cheers

David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 10 janv. 2013 à 03:49, JD jdalecki@tycoint.com a écrit :

Sorry David. I feel a bit embarrassed by this question – you are obviously right - I just did not click that this code is actually creating index and not searching.
Thanks for the reply and clarification.
Regards,
janusz

On Wednesday, January 9, 2013 8:56:45 PM UTC+11, JD wrote:

Hi,
I am trying to use JSON builder to get some documents from elasticsearch db.
IndexResponse response = client.prepareIndex("asset_index", "Asset").setSource(
jsonBuilder().startObject().field("name", "FCC_SRV02").endObject()).execute().actionGet();

I am getting IndexResponse.
How can I convert IndexResponse to SearchResponse so I retrieve SearchHit

Regards,
Janusz
--

--

Yep - correct.
Thanks David for all your replies.
Regards,
Janusz

On Wednesday, January 9, 2013 8:56:45 PM UTC+11, JD wrote:

Hi,

I am trying to use JSON builder to get some documents from elasticsearch
db.

  IndexResponse response = client.prepareIndex("asset_index", "Asset"

).setSource(

      *jsonBuilder*().startObject().field("name", "FCC_SRV02"

).endObject()).execute().actionGet();

I am getting IndexResponse.

How can I convert IndexResponse to SearchResponse so I retrieve *SearchHit

Regards,

Janusz

--