# "Grouping"

**URL:** <https://discuss.elastic.co/t/grouping/14472>\
**Category:** Elasticsearch\
**Created:** [November 19, 2013, 5:44pm UTC](https://discuss.elastic.co/t/grouping/14472 "2013-11-19T17:44:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Josef\_Rousek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/josef_rousek/32/56948_2.png) [@Josef\_Rousek](https://discuss.elastic.co/u/Josef_Rousek)\
**Post date:** [November 19, 2013, 5:44pm UTC](https://discuss.elastic.co/t/grouping/14472/1 "2013-11-19T17:44:50Z")

</div>

Hello,  
I'm not sure how to solve following problem.  
I have following data and I need to separate negative and positive _values_and then group them by tags.  
I used terms\_stats facet to get the \*total \*field, but I'm lost in  
possibilities how to get _income_ and _expense_ fields.

{  
"id": 10337,  
"items": [  
{  
"id": 1,  
"tags": [  
"tag1"  
],  
"value": 305,  
},  
{  
"id": 2,  
"tags": [  
"tag1"  
],  
"value": -64  
}  
]  
}

_Expected result is something like this:_

{  
"tag1":  
{  
"income": 305,  
"expense": -64,  
"total": 241  
}  
}

Thank you

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 19, 2013, 6:26pm UTC](https://discuss.elastic.co/t/grouping/14472/2 "2013-11-19T18:26:56Z")

</div>

You are probably thinking of field collapsing, which will hopefully be  
available in some form in elasticsearch 1.0.

--  
Ivan

On Tue, Nov 19, 2013 at 9:44 AM, Josef Rousek [josef.rousek@gmail.com](mailto:josef.rousek@gmail.com)wrote:

> Hello,  
> I'm not sure how to solve following problem.  
> I have following data and I need to separate negative and positive  
> _values_ and then group them by tags.  
> I used terms\_stats facet to get the \*total \*field, but I'm lost in  
> possibilities how to get _income_ and _expense_ fields.
> 
> {  
> "id": 10337,  
> "items": [  
> {  
> "id": 1,  
> "tags": [  
> "tag1"  
> ],  
> "value": 305,  
> },  
> {  
> "id": 2,  
> "tags": [  
> "tag1"  
> ],  
> "value": -64  
> }  
> ]  
> }
> 
> _Expected result is something like this:_
> 
> {  
> "tag1":  
> {  
> "income": 305,  
> "expense": -64,  
> "total": 241  
> }  
> }
> 
> Thank you
> 
> --  
> 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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:06am UTC](https://discuss.elastic.co/t/grouping/14472/3 "2017-07-06T02:06:10Z")

</div>

Closed on July 6, 2017, 2:06am UTC


