# Converting IndexResponse to SearchResponse

**URL:** <https://discuss.elastic.co/t/converting-indexresponse-to-searchresponse/10277>\
**Category:** Elasticsearch\
**Created:** [January 9, 2013, 9:56am UTC](https://discuss.elastic.co/t/converting-indexresponse-to-searchresponse/10277 "2013-01-09T09:56:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 9, 2013, 9:56am UTC](https://discuss.elastic.co/t/converting-indexresponse-to-searchresponse/10277/1 "2013-01-09T09:56:45Z")

</div>

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

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 9, 2013, 10:08am UTC](https://discuss.elastic.co/t/converting-indexresponse-to-searchresponse/10277/2 "2013-01-09T10:08:42Z")

</div>

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/ex1/IndexTest.java#L69](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#L268](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](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](mailto: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://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 10, 2013, 2:49am UTC](https://discuss.elastic.co/t/converting-indexresponse-to-searchresponse/10277/3 "2013-01-10T02:49:20Z")

</div>

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

--

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2013, 2:53am UTC](https://discuss.elastic.co/t/converting-indexresponse-to-searchresponse/10277/4 "2013-01-10T02:53:25Z")

</div>

Just a new clarification about the terms you use.  
This command does not _create an index_ but _index a document_.

## Cheers

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

Le 10 janv. 2013 à 03:49, JD [jdalecki@tycoint.com](mailto: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  
> --

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 10, 2013, 3:02am UTC](https://discuss.elastic.co/t/converting-indexresponse-to-searchresponse/10277/5 "2013-01-10T03:02:45Z")

</div>

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

--

---

<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, 2:57am UTC](https://discuss.elastic.co/t/converting-indexresponse-to-searchresponse/10277/6 "2017-07-06T02:57:05Z")

</div>


