# Multi field aggregation

**URL:** https://discuss.elastic.co/t/multi-field-aggregation/10620
**Category:** Elasticsearch
**Created:** [February 4, 2013, 9:08pm UTC](https://discuss.elastic.co/t/multi-field-aggregation/10620 "2013-02-04T21:08:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Seth\_Mason](https://avatars.discourse-cdn.com/v4/letter/s/df705f/32.png) [@Seth\_Mason](https://discuss.elastic.co/u/Seth_Mason)
#### Post date: [February 4, 2013, 9:08pm UTC](https://discuss.elastic.co/t/multi-field-aggregation/10620/1 "2013-02-04T21:08:11Z")

</div>

I have documents that look like this:

{  
"latency": 10,  
"ttl" : 50,  
"fwm" : 0x7  
},  
{  
"latency": 13,  
"ttl" : 65,  
"fwm" : 0x8  
}

What I'm after is the top N of the combined ttl and fwm fields (similar to  
a group by with a count in SQL). So, I'd get (if I only had the two data  
points above):

50 0x7 1  
65 0x8 1

Is there a way to get a aggregate count of multiple fields ?

I tried using the facets with a script\_field to combine the two fields but  
that kept returning 500 errors (though it might have been something else  
causing that).

Thanks advance for any answers.

--  
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: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [February 5, 2013, 10:16am UTC](https://discuss.elastic.co/t/multi-field-aggregation/10620/2 "2013-02-05T10:16:11Z")

</div>

Hi Seth

> {  
> "latency": 10,  
> "ttl" : 50,  
> "fwm" : 0x7  
> },  
> {  
> "latency": 13,  
> "ttl" : 65,  
> "fwm" : 0x8  
> }
> 
> What I'm after is the top N of the combined ttl and fwm  
> fields (similar to a group by with a count in SQL). So, I'd get (if I  
> only had the two data points above):
> 
> 50 0x7 1  
> 65 0x8 1

It sounds like what you need is a terms facet. But, you're wanting to  
combine the value from two different fields, which the terms facet  
doesn't support out of the box.

Two options:

1. index the combination of ttl and fwm in another field, and run the  
facets on that
2. use a script\_field in the terms facet to output the concatenation of  
ttl and fwm

Note, option 2 will be slower than option 1

clint

> Is there a way to get a aggregate count of multiple fields ?
> 
> I tried using the facets with a script\_field to combine the two fields  
> but that kept returning 500 errors (though it might have been  
> something else causing that).
> 
> Thanks advance for any answers.
> 
> --  
> 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:53am UTC](https://discuss.elastic.co/t/multi-field-aggregation/10620/3 "2017-07-06T02:53:01Z")

</div>


