# Streamlining Result JSON

**URL:** <https://discuss.elastic.co/t/streamlining-result-json/5838>\
**Category:** Elasticsearch\
**Created:** [November 10, 2011, 3:52pm UTC](https://discuss.elastic.co/t/streamlining-result-json/5838 "2011-11-10T15:52:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Schnyder](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@Schnyder](https://discuss.elastic.co/u/Schnyder)\
**Post date:** [November 10, 2011, 3:52pm UTC](https://discuss.elastic.co/t/streamlining-result-json/5838/1 "2011-11-10T15:52:58Z")

</div>

Is there any way to transform result JSON prior to returning it? I'm trying to optimize the performance of our system, which relies on a sometime narrow pipe between a web server and an ElasticSearch index cluster. I've found that the transmission of ElasticSearch result JSON back to the WebServers can hurt performance in some extreme situations, due to restricted bandwidth.

Is there any facility in Elasticsearch (besides specifying the fields I'm interested in returning) to further reduce the amount of JSON being returned? For instance, my immediate need is for the results to return merely an integer ID and distance value for each matching document. But the result JSON is also including the index name and type in every hit. When dealing with very large result sets, the JSON formatting overhead can add up. Below is an example of some of the current JSON I'm getting back, followed by an example of JSON I really need:

**Current Output Format Sample:**  
{  
took: 95,  
timed\_out: false,  
\_shards: {  
total: 5,  
successful: 5,  
failed: 0,  
},  
hits: {  
total: 1457,  
max\_score: null,  
hits: [  
{  
\_index: "myindex",  
\_type: "mytype",  
\_id: "1849116",  
\_score: null,  
fields: {  
id: 1849116  
},  
sort: [  
0.39546441522778686  
]  
},  
{  
\_index: "myindex",  
\_type: "mytype",  
\_id: "723963",  
\_score: null,  
fields: {  
id: 723963  
}  
sort: [  
0.47589688265048097  
]  
},  
...

**JSON I'd Like to Receive:**  
{  
hits: {  
total: 1457,  
max\_score: null,  
hits: [  
{id: 1849116, sort: 0.39546441522778686},  
{id: 723963, sort: 0.47589688265048097},  
...

Any suggestions/recommendations on how to accomplish this?

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![Gabriel\_Farrell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_farrell/32/3337_2.png) [@Gabriel\_Farrell](https://discuss.elastic.co/u/Gabriel_Farrell)\
**Post date:** [November 10, 2011, 5:49pm UTC](https://discuss.elastic.co/t/streamlining-result-json/5838/2 "2011-11-10T17:49:53Z")

</div>

Would it be possible to set up a Node.js proxy on the Elasticsearch  
side of that narrow pipe? That way you could transform the API in  
whatever way you want.

On Thu, Nov 10, 2011 at 10:52 AM, Schnyder  
[chris.schnyder@cardinal-holdings.com](mailto:chris.schnyder@cardinal-holdings.com) wrote:

> Is there any way to transform result JSON prior to returning it? I'm trying  
> to optimize the performance of our system, which relies on a sometime narrow  
> pipe between a web server and an Elasticsearch index cluster. I've found  
> that the transmission of Elasticsearch result JSON back to the WebServers  
> can hurt performance in some extreme situations, due to restricted  
> bandwidth. Is there any facility in Elasticsearch (besides specifying the  
> fields I'm interested in returning) to further reduce the amount of JSON  
> being returned? For instance, my immediate need is for the results to return  
> merely an integer ID and distance value for each matching document. But the  
> result JSON is also including the index name and type in every hit. When  
> dealing with very large result sets, the JSON formatting overhead can add  
> up. Below is an example of some of the current JSON I'm getting back,  
> followed by an example of JSON I really need: Current Output Format Sample:
> 
> {  
> took: 95,  
> timed\_out: false,  
> \_shards: {  
> total: 5,  
> successful: 5,  
> failed: 0,  
> },  
> hits: {  
> total: 1457,  
> max\_score: null,  
> hits: [  
> {  
> \_index: "myindex",  
> \_type: "mytype",  
> \_id: "1849116",  
> \_score: null,  
> fields: {  
> id: 1849116  
> },  
> sort: [  
> 0.39546441522778686  
> ]  
> },  
> {  
> \_index: "myindex",  
> \_type: "mytype",  
> \_id: "723963",  
> \_score: null,  
> fields: {  
> id: 723963  
> }  
> sort: [  
> 0.47589688265048097  
> ]  
> },  
> ...
> 
> JSON I'd Like to Receive:
> 
> {  
> hits: {  
> total: 1457,  
> max\_score: null,  
> hits: [  
> {id: 1849116, sort: 0.39546441522778686},  
> {id: 723963, sort: 0.47589688265048097},  
> ...
> 
> Any suggestions/recommendations on how to accomplish this? Thanks, Chris
> 
> * * *
> 
> View this message in context: Streamlining Result JSON  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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, 3:49am UTC](https://discuss.elastic.co/t/streamlining-result-json/5838/3 "2017-07-06T03:49:08Z")

</div>


