# Facet query issue

**URL:** <https://discuss.elastic.co/t/facet-query-issue/14788>\
**Category:** Elasticsearch\
**Created:** [December 10, 2013, 8:52am UTC](https://discuss.elastic.co/t/facet-query-issue/14788 "2013-12-10T08:52:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhiage](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@abhiage](https://discuss.elastic.co/u/abhiage)\
**Post date:** [December 10, 2013, 8:52am UTC](https://discuss.elastic.co/t/facet-query-issue/14788/1 "2013-12-10T08:52:11Z")

</div>

I have following data in my index

Action : "added" Product\_ID : 123  
Action : "added" Product\_ID : 124  
Action : "removed" Product\_ID : 124  
Action : "purchased" Product\_ID : 123  
Action : "added" Product\_ID : 123

I want to count number of products added or removed by product\_ID wise.  
e.g for Product\_ID : 123 added = 2 and removed =0.  
I can achieve this by firing two separate query for added and removed  
respectively using facets.

How can i get above output using single query?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/124fbab0-01e9-4b95-9a45-cefdb1b66ce0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/124fbab0-01e9-4b95-9a45-cefdb1b66ce0%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 10, 2013, 9:49am UTC](https://discuss.elastic.co/t/facet-query-issue/14788/2 "2013-12-10T09:49:03Z")

</div>

Hey,

you could use term scripts to combine the fields together, see

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

--Alex

On Tue, Dec 10, 2013 at 9:52 AM, abhi patel [abhiage@gmail.com](mailto:abhiage@gmail.com) wrote:

> I have following data in my index
> 
> Action : "added" Product\_ID : 123  
> Action : "added" Product\_ID : 124  
> Action : "removed" Product\_ID : 124  
> Action : "purchased" Product\_ID : 123  
> Action : "added" Product\_ID : 123
> 
> I want to count number of products added or removed by product\_ID wise.  
> e.g for Product\_ID : 123 added = 2 and removed =0.  
> I can achieve this by firing two separate query for added and removed  
> respectively using facets.
> 
> How can i get above output using single query?
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/124fbab0-01e9-4b95-9a45-cefdb1b66ce0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/124fbab0-01e9-4b95-9a45-cefdb1b66ce0%40googlegroups.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8AFY6F5%2B\_mq4ROQjPyWwR6OS2iGqop02tngwJCeitNzw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8AFY6F5%2B_mq4ROQjPyWwR6OS2iGqop02tngwJCeitNzw%40mail.gmail.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:02am UTC](https://discuss.elastic.co/t/facet-query-issue/14788/3 "2017-07-06T02:02:16Z")

</div>


