# Multiple Statistical Facets in one search

**URL:** <https://discuss.elastic.co/t/multiple-statistical-facets-in-one-search/11800>\
**Category:** Elasticsearch\
**Created:** [May 3, 2013, 2:17pm UTC](https://discuss.elastic.co/t/multiple-statistical-facets-in-one-search/11800 "2013-05-03T14:17:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![OffensivelyBad\_2](https://avatars.discourse-cdn.com/v4/letter/o/51bf81/32.png) [@OffensivelyBad\_2](https://discuss.elastic.co/u/OffensivelyBad_2)\
**Post date:** [May 3, 2013, 2:17pm UTC](https://discuss.elastic.co/t/multiple-statistical-facets-in-one-search/11800/1 "2013-05-03T14:17:56Z")

</div>

Hello,

I'm trying to use multiple stats facets in one search like the code below,  
however I'm getting an error message when I attempt to run this. Can  
someone tell me what I'm doing wrong?

curl -XPOST '10.10.48.20:9200/kpi/misdiverts\_by\_lane/\_search?pretty=true'  
-d  
'{  
"query": {  
"match\_all": {}  
},  
"facets": {  
"route\_lane\_misdiverts\_stats": {  
"terms\_stats": {  
"key\_field": "route\_lane",  
"value\_field": "misdiverts",  
"order": "term"  
}  
}  
},  
{  
"actual\_lane\_misdiverts\_stats": {  
"terms\_stats": {  
"key\_field": "actual\_lane",  
"value\_field": "misdiverts",  
"order": "term"  
}  
}  
}  
}'

--  
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:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [May 3, 2013, 5:22pm UTC](https://discuss.elastic.co/t/multiple-statistical-facets-in-one-search/11800/2 "2013-05-03T17:22:32Z")

</div>

all seems to be right. I use may facets including terms\_stats in one call.  
what's the error?

On Friday, May 3, 2013 10:17:56 AM UTC-4, OffensivelyBad wrote:

> Hello,
> 
> I'm trying to use multiple stats facets in one search like the code below,  
> however I'm getting an error message when I attempt to run this. Can  
> someone tell me what I'm doing wrong?
> 
> curl -XPOST '10.10.48.20:9200/kpi/misdiverts\_by\_lane/\_search?pretty=true'  
> -d  
> '{  
> "query": {  
> "match\_all": {}  
> },  
> "facets": {  
> "route\_lane\_misdiverts\_stats": {  
> "terms\_stats": {  
> "key\_field": "route\_lane",  
> "value\_field": "misdiverts",  
> "order": "term"  
> }  
> }  
> },  
> {  
> "actual\_lane\_misdiverts\_stats": {  
> "terms\_stats": {  
> "key\_field": "actual\_lane",  
> "value\_field": "misdiverts",  
> "order": "term"  
> }  
> }  
> }  
> }'

--  
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:** ![OffensivelyBad\_2](https://avatars.discourse-cdn.com/v4/letter/o/51bf81/32.png) [@OffensivelyBad\_2](https://discuss.elastic.co/u/OffensivelyBad_2)\
**Post date:** [May 3, 2013, 8:58pm UTC](https://discuss.elastic.co/t/multiple-statistical-facets-in-one-search/11800/3 "2013-05-03T20:58:17Z")

</div>

I get a verbose error, but it starts like this:

"error" : "SearchPhaseExecutionException[Failed to execute phase [query],  
total failure; shardFailures

On Friday, May 3, 2013 1:22:32 PM UTC-4, AlexR wrote:

> all seems to be right. I use may facets including terms\_stats in one call.  
> what's the error?
> 
> On Friday, May 3, 2013 10:17:56 AM UTC-4, OffensivelyBad wrote:
> 
> > Hello,
> > 
> > I'm trying to use multiple stats facets in one search like the code  
> > below, however I'm getting an error message when I attempt to run this.  
> > Can someone tell me what I'm doing wrong?
> > 
> > curl -XPOST '10.10.48.20:9200/kpi/misdiverts\_by\_lane/\_search?pretty=true'  
> > -d  
> > '{  
> > "query": {  
> > "match\_all": {}  
> > },  
> > "facets": {  
> > "route\_lane\_misdiverts\_stats": {  
> > "terms\_stats": {  
> > "key\_field": "route\_lane",  
> > "value\_field": "misdiverts",  
> > "order": "term"  
> > }  
> > }  
> > },  
> > {  
> > "actual\_lane\_misdiverts\_stats": {  
> > "terms\_stats": {  
> > "key\_field": "actual\_lane",  
> > "value\_field": "misdiverts",  
> > "order": "term"  
> > }  
> > }  
> > }  
> > }'

--  
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:** ![OffensivelyBad\_2](https://avatars.discourse-cdn.com/v4/letter/o/51bf81/32.png) [@OffensivelyBad\_2](https://discuss.elastic.co/u/OffensivelyBad_2)\
**Post date:** [May 3, 2013, 8:59pm UTC](https://discuss.elastic.co/t/multiple-statistical-facets-in-one-search/11800/4 "2013-05-03T20:59:56Z")

</div>

I should also mention that each stats facets works individually, but using  
them together in the same search causes the error.

On Friday, May 3, 2013 4:58:17 PM UTC-4, OffensivelyBad wrote:

> I get a verbose error, but it starts like this:
> 
> "error" : "SearchPhaseExecutionException[Failed to execute phase [query],  
> total failure; shardFailures
> 
> On Friday, May 3, 2013 1:22:32 PM UTC-4, AlexR wrote:
> 
> > all seems to be right. I use may facets including terms\_stats in one  
> > call. what's the error?
> > 
> > On Friday, May 3, 2013 10:17:56 AM UTC-4, OffensivelyBad wrote:
> > 
> > > Hello,
> > > 
> > > I'm trying to use multiple stats facets in one search like the code  
> > > below, however I'm getting an error message when I attempt to run this.  
> > > Can someone tell me what I'm doing wrong?
> > > 
> > > curl -XPOST '10.10.48.20:9200/kpi/misdiverts\_by\_lane/\_search?pretty=true'  
> > > -d  
> > > '{  
> > > "query": {  
> > > "match\_all": {}  
> > > },  
> > > "facets": {  
> > > "route\_lane\_misdiverts\_stats": {  
> > > "terms\_stats": {  
> > > "key\_field": "route\_lane",  
> > > "value\_field": "misdiverts",  
> > > "order": "term"  
> > > }  
> > > }  
> > > },  
> > > {  
> > > "actual\_lane\_misdiverts\_stats": {  
> > > "terms\_stats": {  
> > > "key\_field": "actual\_lane",  
> > > "value\_field": "misdiverts",  
> > > "order": "term"  
> > > }  
> > > }  
> > > }  
> > > }'

--  
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:** ![roytmana](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roytmana/32/44855_2.png) [@roytmana](https://discuss.elastic.co/u/roytmana)\
**Post date:** [May 3, 2013, 9:09pm UTC](https://discuss.elastic.co/t/multiple-statistical-facets-in-one-search/11800/5 "2013-05-03T21:09:16Z")

</div>

you are not using correct format. all facets should be within facets:{}  
object but you have them mixed up. try this (hopefully I did not mess up  
json - hard to see indents in browser)

{  
"query": {  
"match\_all": {}  
},  
"facets": {  
"route\_lane\_misdiverts\_stats": {  
"terms\_stats": {  
"key\_field": "route\_lane",  
"value\_field": "misdiverts",  
"order": "term"  
}  
},  
"actual\_lane\_misdiverts\_stats": {  
"terms\_stats": {  
"key\_field": "actual\_lane",  
"value\_field": "misdiverts",  
"order": "term"  
}  
}  
}  
}

On Friday, May 3, 2013 4:59:56 PM UTC-4, OffensivelyBad wrote:

> I should also mention that each stats facets works individually, but using  
> them together in the same search causes the error.
> 
> On Friday, May 3, 2013 4:58:17 PM UTC-4, OffensivelyBad wrote:
> 
> > I get a verbose error, but it starts like this:
> > 
> > "error" : "SearchPhaseExecutionException[Failed to execute phase [query],  
> > total failure; shardFailures
> > 
> > On Friday, May 3, 2013 1:22:32 PM UTC-4, AlexR wrote:
> > 
> > > all seems to be right. I use may facets including terms\_stats in one  
> > > call. what's the error?
> > > 
> > > On Friday, May 3, 2013 10:17:56 AM UTC-4, OffensivelyBad wrote:
> > > 
> > > > Hello,
> > > > 
> > > > I'm trying to use multiple stats facets in one search like the code  
> > > > below, however I'm getting an error message when I attempt to run this.  
> > > > Can someone tell me what I'm doing wrong?
> > > > 
> > > > curl -XPOST '  
> > > > 10.10.48.20:9200/kpi/misdiverts\_by\_lane/\_search?pretty=true' -d  
> > > > '{  
> > > > "query": {  
> > > > "match\_all": {}  
> > > > },  
> > > > "facets": {  
> > > > "route\_lane\_misdiverts\_stats": {  
> > > > "terms\_stats": {  
> > > > "key\_field": "route\_lane",  
> > > > "value\_field": "misdiverts",  
> > > > "order": "term"  
> > > > }  
> > > > }  
> > > > },  
> > > > {  
> > > > "actual\_lane\_misdiverts\_stats": {  
> > > > "terms\_stats": {  
> > > > "key\_field": "actual\_lane",  
> > > > "value\_field": "misdiverts",  
> > > > "order": "term"  
> > > > }  
> > > > }  
> > > > }  
> > > > }'

--  
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:38am UTC](https://discuss.elastic.co/t/multiple-statistical-facets-in-one-search/11800/6 "2017-07-06T02:38:24Z")

</div>


