# Querying docs array type elemnts with multiple fields

**URL:** <https://discuss.elastic.co/t/querying-docs-array-type-elemnts-with-multiple-fields/12989>\
**Category:** Elasticsearch\
**Created:** [July 29, 2013, 6:22pm UTC](https://discuss.elastic.co/t/querying-docs-array-type-elemnts-with-multiple-fields/12989 "2013-07-29T18:22:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavan\_achanta](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@pavan\_achanta](https://discuss.elastic.co/u/pavan_achanta)\
**Post date:** [July 29, 2013, 6:22pm UTC](https://discuss.elastic.co/t/querying-docs-array-type-elemnts-with-multiple-fields/12989/1 "2013-07-29T18:22:21Z")

</div>

I have the following 2 docs in the index:

curl -XPUT '[http://localhost:9200/tweet/100](http://localhost:9200/tweet/100)' -d '{  
"tweet" : {  
"message" : "some arrays in this tweet...",  
"lists" : [  
{  
"name" : "prog\_list",  
"description" : "programming list",  
"labels" : ["maybe","fine"]  
},  
{  
"name" : "cool\_list",  
"description" : "cool stuff list",  
"labels" : ["good","nice"]  
}  
]  
}  
}'

curl -XPUT '[http://localhost:9200/tweet/200](http://localhost:9200/tweet/200)' -d '{  
"tweet" : {  
"message" : "some arrays in this tweet...",  
"lists" : [  
{  
"name" : "prog\_list",  
"description" : "programming list",  
"labels" : ["good","nice"]  
},  
{  
"name" : "cool\_list",  
"description" : "cool stuff list",  
"labels" : ["pos","neg"]  
}  
]  
}  
}'

Now I like to return only the docs that have an array element of type lists  
with name=prog\_list and labels has "good" i.e. doc 200 above.  
but the following query returns both docs:

{  
"query": {  
"bool": {  
"should": [  
{  
"term": {  
"name": "prog\_list"  
}  
},  
{  
"term": {  
"labels": "good"  
}  
}  
],  
"minimum\_should\_match": 2  
}  
}  
}

Is there a way we can apply the the above query to the same lists element?

Thanks!  
Pavan

--  
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:** ![pavan\_achanta](https://avatars.discourse-cdn.com/v4/letter/p/53a042/32.png) [@pavan\_achanta](https://discuss.elastic.co/u/pavan_achanta)\
**Post date:** [July 29, 2013, 7:33pm UTC](https://discuss.elastic.co/t/querying-docs-array-type-elemnts-with-multiple-fields/12989/2 "2013-07-29T19:33:26Z")

</div>

Seems like nested mapping is the only way we can avoid cross obj search.

Something we cannot afford to do given the voulme of nested docs that will  
be created for each doc.

On Monday, 29 July 2013 11:22:21 UTC-7, pavan achanta wrote:

> I have the following 2 docs in the index:
> 
> curl -XPUT '[http://localhost:9200/tweet/100](http://localhost:9200/tweet/100)' -d '{  
> "tweet" : {  
> "message" : "some arrays in this tweet...",  
> "lists" : [  
> {  
> "name" : "prog\_list",  
> "description" : "programming list",  
> "labels" : ["maybe","fine"]  
> },  
> {  
> "name" : "cool\_list",  
> "description" : "cool stuff list",  
> "labels" : ["good","nice"]  
> }  
> ]  
> }  
> }'
> 
> curl -XPUT '[http://localhost:9200/tweet/200](http://localhost:9200/tweet/200)' -d '{  
> "tweet" : {  
> "message" : "some arrays in this tweet...",  
> "lists" : [  
> {  
> "name" : "prog\_list",  
> "description" : "programming list",  
> "labels" : ["good","nice"]  
> },  
> {  
> "name" : "cool\_list",  
> "description" : "cool stuff list",  
> "labels" : ["pos","neg"]  
> }  
> ]  
> }  
> }'
> 
> Now I like to return only the docs that have an array element of type  
> lists with name=prog\_list and labels has "good" i.e. doc 200 above.  
> but the following query returns both docs:
> 
> {  
> "query": {  
> "bool": {  
> "should": [  
> {  
> "term": {  
> "name": "prog\_list"  
> }  
> },  
> {  
> "term": {  
> "labels": "good"  
> }  
> }  
> ],  
> "minimum\_should\_match": 2  
> }  
> }  
> }
> 
> Is there a way we can apply the the above query to the same lists element?
> 
> Thanks!  
> Pavan

--  
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:23am UTC](https://discuss.elastic.co/t/querying-docs-array-type-elemnts-with-multiple-fields/12989/3 "2017-07-06T02:23:56Z")

</div>


