# Change the structure of response json

**URL:** <https://discuss.elastic.co/t/change-the-structure-of-response-json/2924>\
**Category:** Elasticsearch\
**Created:** [April 21, 2010, 2:41am UTC](https://discuss.elastic.co/t/change-the-structure-of-response-json/2924 "2010-04-21T02:41:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tfreitas](https://avatars.discourse-cdn.com/v4/letter/t/bbe5ce/32.png) [@tfreitas](https://discuss.elastic.co/u/tfreitas)\
**Post date:** [April 21, 2010, 2:41am UTC](https://discuss.elastic.co/t/change-the-structure-of-response-json/2924/1 "2010-04-21T02:41:18Z")

</div>

Hello Shay,

I have a years using compass, now I see elasticsearch, I want to play  
with it.

With ElasticSearch I could do:

1. in "search" return a json structure different from the index?.

Example:  
index:  
{  
"User": "kimchy"  
"PostData": "2009-11-15T14: 12:12"  
"Message": "trying out Elastic Search"  
}

and search:  
{  
"\_shards": {  
"Total": 5,  
"Successful": 5,  
"Failed": 0  
}  
"Hits": {  
"Total": 1,  
"Hits": [  
{  
"\_index": "Twitter"  
"\_type": "Tweet"  
"\_id": "1"  
"\_source": {  
"User": "kimchy"  
"Today": "2010-04-15T14: 12:12", / / calculated  
dynamically, today's date  
"Message": "trying out Elastic Search"  
"Days": 180 / / calculated dynamically, the rest  
of today-postData  
}  
}  
]  
}  
}

Moreover, in some cases might omit some control information, do not  
send "\_index", "\_type", and "\_id". This is possible?

1. I'm thinking that elasticsearch respond directly to requests from a  
browser.  
A website made jsonp requests to search in elasticsearch, and respond  
json for rendering in browser with PURE ([http://beebole.com/pure/](http://beebole.com/pure/))  
Think this solution is viable

Thanks, and sorry for my language mistakes

---

<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:** [April 21, 2010, 5:35pm UTC](https://discuss.elastic.co/t/change-the-structure-of-response-json/2924/2 "2010-04-21T17:35:39Z")

</div>

Hi,

Regarding the first question, I am thinking of something very similar to  
enable in elasticsearch. Basically, allow to augment the results with more  
information. I have an idea on how to do this, but it will be at least 0.8  
before I will try and tackle this. For now, you can front elasticsearch with  
your own server that augments the data.

cheers,  
shay.banon

On Wed, Apr 21, 2010 at 5:41 AM, tfreitas [tfreitas@gmail.com](mailto:tfreitas@gmail.com) wrote:

> Hello Shay,
> 
> I have a years using compass, now I see elasticsearch, I want to play  
> with it.
> 
> With Elasticsearch I could do:
> 
> 1. in "search" return a json structure different from the index?.
> 
> Example:  
> index:  
> {  
> "User": "kimchy"  
> "PostData": "2009-11-15T14: 12:12"  
> "Message": "trying out Elastic Search"  
> }
> 
> and search:  
> {  
> "\_shards": {  
> "Total": 5,  
> "Successful": 5,  
> "Failed": 0  
> }  
> "Hits": {  
> "Total": 1,  
> "Hits": [  
> {  
> "\_index": "Twitter"  
> "\_type": "Tweet"  
> "\_id": "1"  
> "\_source": {  
> "User": "kimchy"  
> "Today": "2010-04-15T14: 12:12", / / calculated  
> dynamically, today's date  
> "Message": "trying out Elastic Search"  
> "Days": 180 / / calculated dynamically, the rest  
> of today-postData  
> }  
> }  
> ]  
> }  
> }
> 
> Moreover, in some cases might omit some control information, do not  
> send "\_index", "\_type", and "\_id". This is possible?
> 
> 1. I'm thinking that elasticsearch respond directly to requests from a  
> browser.  
> A website made jsonp requests to search in elasticsearch, and respond  
> json for rendering in browser with PURE ([http://beebole.com/pure/](http://beebole.com/pure/))  
> Think this solution is viable
> 
> Thanks, and sorry for my language mistakes

---

<div class="post-metadata">

**Author:** ![tfreitas](https://avatars.discourse-cdn.com/v4/letter/t/bbe5ce/32.png) [@tfreitas](https://discuss.elastic.co/u/tfreitas)\
**Post date:** [April 22, 2010, 2:02am UTC](https://discuss.elastic.co/t/change-the-structure-of-response-json/2924/3 "2010-04-22T02:02:19Z")

</div>

What do you think about having "templates" response on the server?.  
Could do this as a module in elasticsearch?

On Apr 21, 1:35 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Hi,
> 
> Regarding the first question, I am thinking of something very similar to  
> enable in elasticsearch. Basically, allow to augment the results with more  
> information. I have an idea on how to do this, but it will be at least 0.8  
> before I will try and tackle this. For now, you can front elasticsearch with  
> your own server that augments the data.
> 
> cheers,  
> shay.banon
> 
> On Wed, Apr 21, 2010 at 5:41 AM, tfreitas [tfrei...@gmail.com](mailto:tfrei...@gmail.com) wrote:
> 
> > Hello Shay,
> 
> > I have a years using compass, now I see elasticsearch, I want to play  
> > with it.
> 
> > With Elasticsearch I could do:
> > 
> > 1. in "search" return a json structure different from the index?.
> 
> > Example:  
> > index:  
> > {  
> > "User": "kimchy"  
> > "PostData": "2009-11-15T14: 12:12"  
> > "Message": "trying out Elastic Search"  
> > }
> 
> > and search:  
> > {  
> > "\_shards": {  
> > "Total": 5,  
> > "Successful": 5,  
> > "Failed": 0  
> > }  
> > "Hits": {  
> > "Total": 1,  
> > "Hits": [  
> > {  
> > "\_index": "Twitter"  
> > "\_type": "Tweet"  
> > "\_id": "1"  
> > "\_source": {  
> > "User": "kimchy"  
> > "Today": "2010-04-15T14: 12:12", / / calculated  
> > dynamically, today's date  
> > "Message": "trying out Elastic Search"  
> > "Days": 180 / / calculated dynamically, the rest  
> > of today-postData  
> > }  
> > }  
> > ]  
> > }  
> > }
> 
> > Moreover, in some cases might omit some control information, do not  
> > send "\_index", "\_type", and "\_id". This is possible?
> 
> > 1. I'm thinking that elasticsearch respond directly to requests from a  
> > browser.  
> > A website made jsonp requests to search in elasticsearch, and respond  
> > json for rendering in browser with PURE ([http://beebole.com/pure/](http://beebole.com/pure/))  
> > Think this solution is viable
> 
> > Thanks, and sorry for my language mistakes

---

<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:** [April 22, 2010, 7:15am UTC](https://discuss.elastic.co/t/change-the-structure-of-response-json/2924/4 "2010-04-22T07:15:16Z")

</div>

This can be done, but will be less powerful then what I suggested since in  
the template, you will only have access to the response you got, and not  
additional data (for example, when searching). This can also be developed as  
a plugin, btw.

cheers,  
shay.banon

On Thu, Apr 22, 2010 at 5:02 AM, tfreitas [tfreitas@gmail.com](mailto:tfreitas@gmail.com) wrote:

> What do you think about having "templates" response on the server?.  
> Could do this as a module in elasticsearch?
> 
> On Apr 21, 1:35 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> 
> > Hi,
> > 
> > Regarding the first question, I am thinking of something very similar to  
> > enable in elasticsearch. Basically, allow to augment the results with  
> > more  
> > information. I have an idea on how to do this, but it will be at least  
> > 0.8  
> > before I will try and tackle this. For now, you can front elasticsearch  
> > with  
> > your own server that augments the data.
> > 
> > cheers,  
> > shay.banon
> > 
> > On Wed, Apr 21, 2010 at 5:41 AM, tfreitas [tfrei...@gmail.com](mailto:tfrei...@gmail.com) wrote:
> > 
> > > Hello Shay,
> > 
> > > I have a years using compass, now I see elasticsearch, I want to play  
> > > with it.
> > 
> > > With Elasticsearch I could do:
> > > 
> > > 1. in "search" return a json structure different from the index?.
> > 
> > > Example:  
> > > index:  
> > > {  
> > > "User": "kimchy"  
> > > "PostData": "2009-11-15T14: 12:12"  
> > > "Message": "trying out Elastic Search"  
> > > }
> > 
> > > and search:  
> > > {  
> > > "\_shards": {  
> > > "Total": 5,  
> > > "Successful": 5,  
> > > "Failed": 0  
> > > }  
> > > "Hits": {  
> > > "Total": 1,  
> > > "Hits": [  
> > > {  
> > > "\_index": "Twitter"  
> > > "\_type": "Tweet"  
> > > "\_id": "1"  
> > > "\_source": {  
> > > "User": "kimchy"  
> > > "Today": "2010-04-15T14: 12:12", / / calculated  
> > > dynamically, today's date  
> > > "Message": "trying out Elastic Search"  
> > > "Days": 180 / / calculated dynamically, the rest  
> > > of today-postData  
> > > }  
> > > }  
> > > ]  
> > > }  
> > > }
> > 
> > > Moreover, in some cases might omit some control information, do not  
> > > send "\_index", "\_type", and "\_id". This is possible?
> > 
> > > 1. I'm thinking that elasticsearch respond directly to requests from a  
> > > browser.  
> > > A website made jsonp requests to search in elasticsearch, and respond  
> > > json for rendering in browser with PURE ([http://beebole.com/pure/](http://beebole.com/pure/))  
> > > Think this solution is viable
> > 
> > > Thanks, and sorry for my language mistakes

---

<div class="post-metadata">

**Author:** ![tfreitas](https://avatars.discourse-cdn.com/v4/letter/t/bbe5ce/32.png) [@tfreitas](https://discuss.elastic.co/u/tfreitas)\
**Post date:** [April 22, 2010, 3:10pm UTC](https://discuss.elastic.co/t/change-the-structure-of-response-json/2924/5 "2010-04-22T15:10:10Z")

</div>

ok, I'm going to use a server front, and watch out for this  
functionality you mention, would be great.  
Thanks for your work and effort

On Apr 22, 3:15 am, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> This can be done, but will be less powerful then what I suggested since in  
> the template, you will only have access to the response you got, and not  
> additional data (for example, when searching). This can also be developed as  
> a plugin, btw.
> 
> cheers,  
> shay.banon
> 
> On Thu, Apr 22, 2010 at 5:02 AM, tfreitas [tfrei...@gmail.com](mailto:tfrei...@gmail.com) wrote:
> 
> > What do you think about having "templates" response on the server?.  
> > Could do this as a module in elasticsearch?
> 
> > On Apr 21, 1:35 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:
> > 
> > > Hi,
> 
> > > Regarding the first question, I am thinking of something very similar to  
> > > enable in elasticsearch. Basically, allow to augment the results with  
> > > more  
> > > information. I have an idea on how to do this, but it will be at least  
> > > 0.8  
> > > before I will try and tackle this. For now, you can front elasticsearch  
> > > with  
> > > your own server that augments the data.
> 
> > > cheers,  
> > > shay.banon
> 
> > > On Wed, Apr 21, 2010 at 5:41 AM, tfreitas [tfrei...@gmail.com](mailto:tfrei...@gmail.com) wrote:
> > > 
> > > > Hello Shay,
> 
> > > > I have a years using compass, now I see elasticsearch, I want to play  
> > > > with it.
> 
> > > > With Elasticsearch I could do:
> > > > 
> > > > 1. in "search" return a json structure different from the index?.
> 
> > > > Example:  
> > > > index:  
> > > > {  
> > > > "User": "kimchy"  
> > > > "PostData": "2009-11-15T14: 12:12"  
> > > > "Message": "trying out Elastic Search"  
> > > > }
> 
> > > > and search:  
> > > > {  
> > > > "\_shards": {  
> > > > "Total": 5,  
> > > > "Successful": 5,  
> > > > "Failed": 0  
> > > > }  
> > > > "Hits": {  
> > > > "Total": 1,  
> > > > "Hits": [  
> > > > {  
> > > > "\_index": "Twitter"  
> > > > "\_type": "Tweet"  
> > > > "\_id": "1"  
> > > > "\_source": {  
> > > > "User": "kimchy"  
> > > > "Today": "2010-04-15T14: 12:12", / / calculated  
> > > > dynamically, today's date  
> > > > "Message": "trying out Elastic Search"  
> > > > "Days": 180 / / calculated dynamically, the rest  
> > > > of today-postData  
> > > > }  
> > > > }  
> > > > ]  
> > > > }  
> > > > }
> 
> > > > Moreover, in some cases might omit some control information, do not  
> > > > send "\_index", "\_type", and "\_id". This is possible?
> 
> > > > 1. I'm thinking that elasticsearch respond directly to requests from a  
> > > > browser.  
> > > > A website made jsonp requests to search in elasticsearch, and respond  
> > > > json for rendering in browser with PURE ([http://beebole.com/pure/](http://beebole.com/pure/))  
> > > > Think this solution is viable
> 
> > > > Thanks, and sorry for my language mistakes

---

<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:24am UTC](https://discuss.elastic.co/t/change-the-structure-of-response-json/2924/6 "2017-07-06T04:24:26Z")

</div>


