# Group by operation on two field with term\_stat facet

**URL:** <https://discuss.elastic.co/t/group-by-operation-on-two-field-with-term-stat-facet/10471>\
**Category:** Elasticsearch\
**Created:** [January 23, 2013, 2:43pm UTC](https://discuss.elastic.co/t/group-by-operation-on-two-field-with-term-stat-facet/10471 "2013-01-23T14:43:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmet\_DAL](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ahmet_dal/32/2516_2.png) [@Ahmet\_DAL](https://discuss.elastic.co/u/Ahmet_DAL)\
**Post date:** [January 23, 2013, 2:43pm UTC](https://discuss.elastic.co/t/group-by-operation-on-two-field-with-term-stat-facet/10471/1 "2013-01-23T14:43:10Z")

</div>

I asked a question similar with this topic before. It was about group by on  
two field with term stat by scripting. Igor Motov ansered my question  
(thank him.). The query is like;

"facets": {

```
    "test": {

        "terms": {

            "script": {

                "script_field" : "doc[\"foo\"].value+\"-\"+doc[\"bar\"].value"

            }

        }

    }

}

```

The term part of term\_stat facet is key\_field and the statistical part of  
term\_stat is value\_field if I didn't misunderstand. value\_field can be  
value\_script. Hence we can include our custom scripts. But when I need to  
group by operation on two field I should do it with key\_field which  
represents term facet. But there is no key\_script property which provide  
group by operation on multiple field, in term\_stat. Actually I couldn't  
find this. Is there a way to define key\_field as key\_script to make group  
by operation on two field or can ES support this.

Thank You!

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [February 1, 2013, 3:37pm UTC](https://discuss.elastic.co/t/group-by-operation-on-two-field-with-term-stat-facet/10471/2 "2013-02-01T15:37:31Z")

</div>

Unfortunately, that's current limitation of terms\_stats. I would advise  
again 😉 to just index this pair as a field.

On Wednesday, January 23, 2013 9:43:10 AM UTC-5, Whispered wrote:

> I asked a question similar with this topic before. It was about group by  
> on two field with term stat by scripting. Igor Motov ansered my question  
> (thank him.). The query is like;
> 
> "facets": {
> 
> ```
> "test": {
> 
> "terms": {
> 
> "script": {
> 
> "script_field" : "doc[\"foo\"].value+\"-\"+doc[\"bar\"].value"
> 
> }
> 
> }
> 
> }
> 
> }
> 
> ```
> 
> The term part of term\_stat facet is key\_field and the statistical part of  
> term\_stat is value\_field if I didn't misunderstand. value\_field can be  
> value\_script. Hence we can include our custom scripts. But when I need to  
> group by operation on two field I should do it with key\_field which  
> represents term facet. But there is no key\_script property which provide  
> group by operation on multiple field, in term\_stat. Actually I couldn't  
> find this. Is there a way to define key\_field as key\_script to make group  
> by operation on two field or can ES support this.
> 
> 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:** ![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/group-by-operation-on-two-field-with-term-stat-facet/10471/3 "2017-07-06T02:53:30Z")

</div>


