# How to query a multi-value field?

**URL:** <https://discuss.elastic.co/t/how-to-query-a-multi-value-field/14671>\
**Category:** Elasticsearch\
**Created:** [December 3, 2013, 7:26am UTC](https://discuss.elastic.co/t/how-to-query-a-multi-value-field/14671 "2013-12-03T07:26:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Guo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_guo/32/1725_2.png) [@Daniel\_Guo](https://discuss.elastic.co/u/Daniel_Guo)\
**Post date:** [December 3, 2013, 7:26am UTC](https://discuss.elastic.co/t/how-to-query-a-multi-value-field/14671/1 "2013-12-03T07:26:23Z")

</div>

For example, I have a field which can have multiple value:  
{ "areaId" : [12, 45, 86, 92, 10] }

If I want to index documents whose "areaId" field contains 92, or contains  
92 and 10, what is the best approach?  
Thanks.

--  
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/ce7d61fc-21dd-4355-8d3f-d03bcb54902d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ce7d61fc-21dd-4355-8d3f-d03bcb54902d%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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [December 3, 2013, 7:43am UTC](https://discuss.elastic.co/t/how-to-query-a-multi-value-field/14671/2 "2013-12-03T07:43:24Z")

</div>

Index your document as you have it, then you can query it as follows:

curl -XPOST "[http://localhost:9200/\_search](http://localhost:9200/_search)" -d'  
{  
"query": {  
"filtered": {  
"filter": {  
"bool": {  
"must": [  
{  
"term": {  
"areaId": 92  
}  
},  
{  
"term": {  
"areaId": 10  
}  
}  
]  
}  
}  
}  
}  
}'

On 3 December 2013 08:26, Daniel Guo [daniel5hbs@gmail.com](mailto:daniel5hbs@gmail.com) wrote:

> For example, I have a field which can have multiple value:  
> { "areaId" : [12, 45, 86, 92, 10] }
> 
> If I want to index documents whose "areaId" field contains 92, or contains  
> 92 and 10, what is the best approach?  
> Thanks.
> 
> --  
> 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/ce7d61fc-21dd-4355-8d3f-d03bcb54902d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ce7d61fc-21dd-4355-8d3f-d03bcb54902d%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/CAPt3XKRbsiEoN%2BENKu5%2BJvADzzGEOcC5CDauDG7Pogn3wk5J8A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPt3XKRbsiEoN%2BENKu5%2BJvADzzGEOcC5CDauDG7Pogn3wk5J8A%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:** ![Daniel\_Guo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_guo/32/1725_2.png) [@Daniel\_Guo](https://discuss.elastic.co/u/Daniel_Guo)\
**Post date:** [December 3, 2013, 10:17am UTC](https://discuss.elastic.co/t/how-to-query-a-multi-value-field/14671/3 "2013-12-03T10:17:21Z")

</div>

Hi Clinton:  
It does work, thank you!

On Tuesday, December 3, 2013 3:43:24 PM UTC+8, Clinton Gormley wrote:

> Index your document as you have it, then you can query it as follows:
> 
> curl -XPOST "[http://localhost:9200/\_search](http://localhost:9200/_search)" -d'  
> {  
> "query": {  
> "filtered": {  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "term": {  
> "areaId": 92  
> }  
> },  
> {  
> "term": {  
> "areaId": 10  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }'
> 
> On 3 December 2013 08:26, Daniel Guo \<[danie...@gmail.com](mailto:danie...@gmail.com) \<javascript:\>\>wrote:
> 
> > For example, I have a field which can have multiple value:  
> > { "areaId" : [12, 45, 86, 92, 10] }
> > 
> > If I want to index documents whose "areaId" field contains 92, or  
> > contains 92 and 10, what is the best approach?  
> > Thanks.
> > 
> > --  
> > 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/ce7d61fc-21dd-4355-8d3f-d03bcb54902d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ce7d61fc-21dd-4355-8d3f-d03bcb54902d%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/c3ab53a9-b31f-44ec-8834-b80f01ea796e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c3ab53a9-b31f-44ec-8834-b80f01ea796e%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:** ![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:03am UTC](https://discuss.elastic.co/t/how-to-query-a-multi-value-field/14671/4 "2017-07-06T02:03:40Z")

</div>


