# How can i facets the result

**URL:** https://discuss.elastic.co/t/how-can-i-facets-the-result/18477
**Category:** Elasticsearch
**Created:** [July 4, 2014, 5:43am UTC](https://discuss.elastic.co/t/how-can-i-facets-the-result/18477 "2014-07-04T05:43:49Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![11157](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/11157/32/1293_2.png) [@11157](https://discuss.elastic.co/u/11157)
#### Post date: [July 4, 2014, 5:43am UTC](https://discuss.elastic.co/t/how-can-i-facets-the-result/18477/1 "2014-07-04T05:43:49Z")

</div>

Dear All !  
I have an index, docs like this:  
type1 type2 type3  
A 1 a  
A 1 c  
A 2 c  
B 1 d  
B 3 e  
C 1 e

I wonder find the A with type1 which type2==1 and type2 == 2.

How can get the result? Thx all!

--  
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/1404452629.8967.5.camel%40yancey](https://groups.google.com/d/msgid/elasticsearch/1404452629.8967.5.camel%40yancey).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)
#### Post date: [July 4, 2014, 6:34am UTC](https://discuss.elastic.co/t/how-can-i-facets-the-result/18477/2 "2014-07-04T06:34:15Z")

</div>

Hi ,

You can use bool query to encapsulate various queires. -

> **[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.

Thanks  
Vineeth

On Fri, Jul 4, 2014 at 11:13 AM, yancey [yancey1989@gmail.com](mailto:yancey1989@gmail.com) wrote:

> Dear All !  
> I have an index, docs like this:  
> type1 type2 type3  
> A 1 a  
> A 1 c  
> A 2 c  
> B 1 d  
> B 3 e  
> C 1 e
> 
> I wonder find the A with type1 which type2==1 and type2 == 2.
> 
> How can get the result? Thx all!
> 
> --  
> 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/1404452629.8967.5.camel%40yancey](https://groups.google.com/d/msgid/elasticsearch/1404452629.8967.5.camel%40yancey)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![11157](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/11157/32/1293_2.png) [@11157](https://discuss.elastic.co/u/11157)
#### Post date: [July 4, 2014, 7:28am UTC](https://discuss.elastic.co/t/how-can-i-facets-the-result/18477/3 "2014-07-04T07:28:24Z")

</div>

or bool filter can fech A and B, but I don't want B.

于 2014年07月04日 14:34, vineeth mohan 写道:

> Hi ,
> 
> You can use bool query to encapsulate various queires. -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#query-dsl-bool-query)
> 
> Thanks  
> Vineeth
> 
> On Fri, Jul 4, 2014 at 11:13 AM, yancey \<[yancey1989@gmail.com](mailto:yancey1989@gmail.com)  
> [mailto:yancey1989@gmail.com](mailto:yancey1989@gmail.com)\> wrote:
> 
> ```
> Dear All !
> I have an index, docs like this:
> type1 type2 type3
> A 1 a
> A 1 c
> A 2 c
> B 1 d
> B 3 e
> C 1 e
> 
> I wonder find the A with type1 which type2==1 and type2 == 2.
> 
> How can get the result? Thx all!
> 
> --
> 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%2Bunsubscribe@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/1404452629.8967.5.camel%40yancey.
> For more options, visit https://groups.google.com/d/optout.
> 
> ```
> 
> --  
> 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)  
> [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/53B65798.1050704%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 4, 2014, 7:34am UTC](https://discuss.elastic.co/t/how-can-i-facets-the-result/18477/4 "2014-07-04T07:34:53Z")

</div>

add term (type1, "A") in the must clause.  
add term (type2, "1") and (type2, "2) in the should clause with minimum should match 1.

Should work as you are expecting.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 4 juillet 2014 à 09:29:02, 闫旭 ([yancey1989@gmail.com](mailto:yancey1989@gmail.com)) a écrit:

or bool filter can fech A and B, but I don't want B.

于 2014年07月04日 14:34, vineeth mohan 写道:  
Hi ,

You can use bool query to encapsulate various queires. - [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#query-dsl-bool-query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#query-dsl-bool-query)

Thanks  
Vineeth

On Fri, Jul 4, 2014 at 11:13 AM, yancey [yancey1989@gmail.com](mailto:yancey1989@gmail.com) wrote:  
Dear All !  
I have an index, docs like this:  
type1 type2 type3  
A 1 a  
A 1 c  
A 2 c  
B 1 d  
B 3 e  
C 1 e

I wonder find the A with type1 which type2==1 and type2 == 2.

How can get the result? Thx all!

--  
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/1404452629.8967.5.camel%40yancey](https://groups.google.com/d/msgid/elasticsearch/1404452629.8967.5.camel%40yancey).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/53B65798.1050704%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![11157](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/11157/32/1293_2.png) [@11157](https://discuss.elastic.co/u/11157)
#### Post date: [July 4, 2014, 7:46am UTC](https://discuss.elastic.co/t/how-can-i-facets-the-result/18477/5 "2014-07-04T07:46:47Z")

</div>

Thanks your reply.  
The first :  
add term (type1, "A") in the must clause.  
I want to fech field type1, so i don't know the value of type1 before i  
do the query.

于 2014年07月04日 15:34, David Pilato 写道:

> add term (type1, "A") in the must clause.  
> add term (type2, "1") and (type2, "2) in the should clause with  
> minimum should match 1.
> 
> Should work as you are expecting.
> 
> --  
> _David Pilato_ | /Technical Advocate/ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 4 juillet 2014 à 09:29:02, 闫旭 ([yancey1989@gmail.com](mailto:yancey1989@gmail.com)  
> [mailto:yancey1989@gmail.com](mailto:yancey1989@gmail.com)) a écrit:
> 
> > or bool filter can fech A and B, but I don't want B.
> > 
> > 于 2014年07月04日 14:34, vineeth mohan 写道:
> > 
> > > Hi ,
> > > 
> > > You can use bool query to encapsulate various queires. -  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#query-dsl-bool-query)
> > > 
> > > Thanks  
> > > Vineeth
> > > 
> > > On Fri, Jul 4, 2014 at 11:13 AM, yancey \<[yancey1989@gmail.com](mailto:yancey1989@gmail.com)  
> > > [mailto:yancey1989@gmail.com](mailto:yancey1989@gmail.com)\> wrote:
> > > 
> > > ```
> > > Dear All !
> > > I have an index, docs like this:
> > > type1 type2 type3
> > > A 1 a
> > > A 1 c
> > > A 2 c
> > > B 1 d
> > > B 3 e
> > > C 1 e
> > > 
> > > I wonder find the A with type1 which type2==1 and type2 == 2.
> > > 
> > > How can get the result? Thx all!
> > > 
> > > --
> > > 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%2Bunsubscribe@googlegroups.com>.
> > > To view this discussion on the web visit
> > > https://groups.google.com/d/msgid/elasticsearch/1404452629.8967.5.camel%40yancey.
> > > For more options, visit https://groups.google.com/d/optout.
> > > 
> > > ```
> > > 
> > > --  
> > > 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)  
> > > [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com)  
> > > [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com?utm_medium=email&utm_source=footer).  
> > > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> > 
> > --  
> > 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)  
> > [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com?utm_medium=email&utm_source=footer).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).  
> > --  
> > 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)  
> > [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local)  
> > [https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer).  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/53B65BE7.9000305%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/53B65BE7.9000305%40gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [July 4, 2014, 8:19am UTC](https://discuss.elastic.co/t/how-can-i-facets-the-result/18477/6 "2014-07-04T08:19:36Z")

</div>

Sorry. I don't understand. May be others understand?

Or could you write an example of what you tried so far and post it on [gist.github.com](http://gist.github.com)?  
Have a look at [http://www.elasticsearch.org/help/](http://www.elasticsearch.org/help/)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 4 juillet 2014 à 09:46:59, 闫旭 ([yancey1989@gmail.com](mailto:yancey1989@gmail.com)) a écrit:

Thanks your reply.  
The first :  
add term (type1, "A") in the must clause.  
I want to fech field type1, so i don't know the value of type1 before i do the query.

于 2014年07月04日 15:34, David Pilato 写道:  
add term (type1, "A") in the must clause.  
add term (type2, "1") and (type2, "2) in the should clause with minimum should match 1.

Should work as you are expecting.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 4 juillet 2014 à 09:29:02, 闫旭 ([yancey1989@gmail.com](mailto:yancey1989@gmail.com)) a écrit:

or bool filter can fech A and B, but I don't want B.

于 2014年07月04日 14:34, vineeth mohan 写道:  
Hi ,

You can use bool query to encapsulate various queires. - [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#query-dsl-bool-query](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#query-dsl-bool-query)

Thanks  
Vineeth

On Fri, Jul 4, 2014 at 11:13 AM, yancey [yancey1989@gmail.com](mailto:yancey1989@gmail.com) wrote:  
Dear All !  
I have an index, docs like this:  
type1 type2 type3  
A 1 a  
A 1 c  
A 2 c  
B 1 d  
B 3 e  
C 1 e

I wonder find the A with type1 which type2==1 and type2 == 2.

How can get the result? Thx all!

--  
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/1404452629.8967.5.camel%40yancey](https://groups.google.com/d/msgid/elasticsearch/1404452629.8967.5.camel%40yancey).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

## -- 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/53B65798.1050704%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com). For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

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/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/53B65BE7.9000305%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/53B65BE7.9000305%40gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/etPan.53b66398.238e1f29.2fae%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53b66398.238e1f29.2fae%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![jcl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jcl/32/6605_2.png) [@jcl](https://discuss.elastic.co/u/jcl)
#### Post date: [July 4, 2014, 8:33am UTC](https://discuss.elastic.co/t/how-can-i-facets-the-result/18477/7 "2014-07-04T08:33:04Z")

</div>

You want to get type1 by filtering type2 ? so you should just do an "or"  
filter in your query no ?

> **[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.

Le vendredi 4 juillet 2014 09:47:04 UTC+2, 闫旭 a écrit :

> Thanks your reply.  
> The first :  
> add term (type1, "A") in the must clause.  
> I want to fech field type1, so i don't know the value of type1 before i do  
> the query.
> 
> 于 2014年07月04日 15:34, David Pilato 写道:
> 
> add term (type1, "A") in the must clause.  
> add term (type2, "1") and (type2, "2) in the should clause with minimum  
> should match 1.
> 
> Should work as you are expecting.
> 
> ```
> -- 
> 
> ```
> 
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr  
> [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 4 juillet 2014 à 09:29:02, 闫旭 ([yance...@gmail.com](mailto:yance...@gmail.com) \<javascript:\>) a  
> écrit:
> 
> or bool filter can fech A and B, but I don't want B.
> 
> 于 2014年07月04日 14:34, vineeth mohan 写道:
> 
> Hi ,
> 
> You can use bool query to encapsulate various queires. -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#query-dsl-bool-query)
> 
> Thanks  
> Vineeth
> 
> On Fri, Jul 4, 2014 at 11:13 AM, yancey \<[yance...@gmail.com](mailto:yance...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > Dear All !  
> > I have an index, docs like this:  
> > type1 type2 type3  
> > A 1 a  
> > A 1 c  
> > A 2 c  
> > B 1 d  
> > B 3 e  
> > C 1 e
> > 
> > I wonder find the A with type1 which type2==1 and type2 == 2.
> > 
> > How can get the result? Thx all!
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/1404452629.8967.5.camel%40yancey](https://groups.google.com/d/msgid/elasticsearch/1404452629.8967.5.camel%40yancey)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local)  
> [https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/c9252aab-51df-4b67-ae7d-e3b70d33e8eb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c9252aab-51df-4b67-ae7d-e3b70d33e8eb%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![11157](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/11157/32/1293_2.png) [@11157](https://discuss.elastic.co/u/11157)
#### Post date: [July 4, 2014, 8:53am UTC](https://discuss.elastic.co/t/how-can-i-facets-the-result/18477/8 "2014-07-04T08:53:23Z")

</div>

Hi All!  
May be my description is not clearly,  
for example, i have 7 docs:  
{"type1":"A","type2":"1","type3":"a"}  
{"type1":"A","type2":"2","type3":"a"}  
{"type1":"A","type2":"3","type3":"a"}  
{"type1":"B","type2":"1","type3":"a"}  
{"type1":"B","type2":"3","type3":"a"}  
{"type1":"C","type2":"1","type3":"a"}  
{"type1":"A","type2":"1","type3":"e"}

I want to find the docs:  
group by type1 and type2==1 and type2==2 and distinct type1, the result  
is "A".  
type1:"B" is not the answer, because it's type2 has 1 and 3 but no 1.  
type1:"C" is not the answer ,because it's type2 has only 2.  
so the answer can only be type1:"A", because it's type2 has 1 and 2.

于 2014年07月04日 16:33, [jcl@appiway.com](mailto:jcl@appiway.com) 写道:

> You want to get type1 by filtering type2 ? so you should just do an  
> "or" filter in your query no ?  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-or-filter.html)
> 
> Le vendredi 4 juillet 2014 09:47:04 UTC+2, 闫旭 a écrit :
> 
> ```
> Thanks your reply.
> The first :
> add term (type1, "A") in the must clause.
> I want to fech field type1, so i don't know the value of type1
> before i do the query.
> 
> 于 2014年07月04日 15:34, David Pilato 写道:
> 
> ```
> 
> > ```
> > add term (type1, "A") in the must clause.
> > add term (type2, "1") and (type2, "2) in the should clause with
> > minimum should match 1.
> > 
> > Should work as you are expecting.
> > 
> > -- 
> > *David Pilato* | /Technical Advocate/ | *Elasticsearch.com*
> > @dadoonet <https://twitter.com/dadoonet> | @elasticsearchfr
> > <https://twitter.com/elasticsearchfr>
> > 
> > Le 4 juillet 2014 à 09:29:02, 闫旭 (yance...@gmail.com
> > <javascript:>) a écrit:
> > 
> > ```
> > 
> > > ```
> > > or bool filter can fech A and B, but I don't want B.
> > > 
> > > 于 2014年07月04日 14:34, vineeth mohan 写道:
> > > 
> > > ```
> > > 
> > > > ```
> > > > Hi ,
> > > > 
> > > > You can use bool query to encapsulate various queires. -
> > > > http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#query-dsl-bool-query
> > > > <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#query-dsl-bool-query>
> > > > 
> > > > Thanks
> > > > Vineeth
> > > > 
> > > > On Fri, Jul 4, 2014 at 11:13 AM, yancey <yance...@gmail.com
> > > > <javascript:>> wrote:
> > > > 
> > > > Dear All !
> > > > I have an index, docs like this:
> > > > type1 type2 type3
> > > > A 1 a
> > > > A 1 c
> > > > A 2 c
> > > > B 1 d
> > > > B 3 e
> > > > C 1 e
> > > > 
> > > > I wonder find the A with type1 which type2==1 and type2 == 2.
> > > > 
> > > > How can get the result? Thx all!
> > > > 
> > > > --
> > > > 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 elasticsearc...@googlegroups.com
> > > > <javascript:>.
> > > > To view this discussion on the web visit
> > > > https://groups.google.com/d/msgid/elasticsearch/1404452629.8967.5.camel%40yancey
> > > > <https://groups.google.com/d/msgid/elasticsearch/1404452629.8967.5.camel%40yancey>.
> > > > For more options, visit https://groups.google.com/d/optout
> > > > <https://groups.google.com/d/optout>.
> > > > 
> > > > --
> > > > 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 elasticsearc...@googlegroups.com
> > > > <javascript:>.
> > > > To view this discussion on the web visit
> > > > https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com
> > > > <https://groups.google.com/d/msgid/elasticsearch/CAGdPd5k0%2ByxQK-eutLi6joCRjRU-Etb3cL9YLXyWw6t1WazZYw%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> > > > For more options, visit https://groups.google.com/d/optout
> > > > <https://groups.google.com/d/optout>.
> > > > 
> > > > ```
> > > 
> > > ```
> > > --
> > > 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 elasticsearc...@googlegroups.com <javascript:>.
> > > To view this discussion on the web visit
> > > https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com
> > > <https://groups.google.com/d/msgid/elasticsearch/53B65798.1050704%40gmail.com?utm_medium=email&utm_source=footer>.
> > > For more options, visit https://groups.google.com/d/optout
> > > <https://groups.google.com/d/optout>.
> > > 
> > > ```
> > 
> > ```
> > -- 
> > 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 elasticsearc...@googlegroups.com <javascript:>.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local
> > <https://groups.google.com/d/msgid/elasticsearch/etPan.53b6591d.19495cff.2fae%40MacBook-Air-de-David.local?utm_medium=email&utm_source=footer>.
> > For more options, visit https://groups.google.com/d/optout
> > <https://groups.google.com/d/optout>.
> > 
> > ```
> 
> --  
> 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)  
> [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/c9252aab-51df-4b67-ae7d-e3b70d33e8eb%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c9252aab-51df-4b67-ae7d-e3b70d33e8eb%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c9252aab-51df-4b67-ae7d-e3b70d33e8eb%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c9252aab-51df-4b67-ae7d-e3b70d33e8eb%40googlegroups.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/53B66B83.9040408%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/53B66B83.9040408%40gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:17am UTC](https://discuss.elastic.co/t/how-can-i-facets-the-result/18477/9 "2017-07-06T01:17:55Z")

</div>


