# Nested objects selection

**URL:** <https://discuss.elastic.co/t/nested-objects-selection/12622>\
**Category:** Elasticsearch\
**Created:** [July 2, 2013, 5:24pm UTC](https://discuss.elastic.co/t/nested-objects-selection/12622 "2013-07-02T17:24:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabien\_Chung](https://avatars.discourse-cdn.com/v4/letter/f/b5e925/32.png) [@Fabien\_Chung](https://discuss.elastic.co/u/Fabien_Chung)\
**Post date:** [July 2, 2013, 5:24pm UTC](https://discuss.elastic.co/t/nested-objects-selection/12622/1 "2013-07-02T17:24:08Z")

</div>

hello,

I would like to select only some objects in my nasted objects array.  
Data comes from ([https://gist.github.com/haswalt/a0d78e7c32ec76f03681](https://gist.github.com/haswalt/a0d78e7c32ec76f03681)) :

\*curl -XPOST [http://localhost:9200/cars/documents/1?pretty=true](http://localhost:9200/cars/documents/1?pretty=true) -d'{  
"title": "Test Document 1",  
"slug": "test-document-1",  
"content": "

Some content

",  
"published": "2",  
"version": "2",  
"tags": [  
{  
"name": "Cars",  
"slug": "cars",  
"type": 101  
},  
{  
"name": "News",  
"slug": "news",  
"type": 102  
}  
]  
}'

curl -XPOST [http://localhost:9200/cars/documents/2?pretty=true](http://localhost:9200/cars/documents/2?pretty=true) -d'{  
"title": "Test Document 2",  
"slug": "test-document-2",  
"content": "

Some content

",  
"published": "2",  
"version": "2",  
"tags": [  
{  
"name": "Cars",  
"slug": "cars",  
"type": 101  
},  
{  
"name": "Reviews",  
"slug": "reviews",  
"type": 102  
}  
]  
}'

curl -XPOST [http://localhost:9200/cars/documents/3?pretty=true](http://localhost:9200/cars/documents/3?pretty=true) -d'{  
"title": "Test Document 3",  
"slug": "test-document-3",  
"content": "

Some content

",  
"published": "2",  
"version": "2",  
"tags": [  
{  
"name": "Cars",  
"slug": "cars",  
"type": 101  
},  
{  
"name": "Reviews",  
"slug": "reviews",  
"type": 102  
}  
]  
}'

curl -XPOST [http://localhost:9200/cars/documents/4?pretty=true](http://localhost:9200/cars/documents/4?pretty=true) -d'{  
"title": "Test Document 4",  
"slug": "test-document-4",  
"content": "

Some content

",  
"published": 0,  
"version": 2,  
"tags": [  
{  
"name": "Cars",  
"slug": "cars",  
"type": 101  
},  
{  
"name": "Reviews",  
"slug": "reviews",  
"type": 102  
}  
]  
}'

curl -XPOST [http://localhost:9200/cars/documents/5?pretty=true](http://localhost:9200/cars/documents/5?pretty=true) -d'{  
"title": "Test Document 5",  
"slug": "test-document-5",  
"content": "

Some content

",  
"published": "2",  
"version": "2",  
"tags": [  
{  
"name": "Cars",  
"slug": "cars",  
"type": 101  
},  
{  
"name": "Reviews",  
"slug": "reviews",  
"type": 102  
}  
]  
}'  
curl -XPOST [http://localhost:9200/cars/documents/6?pretty=true](http://localhost:9200/cars/documents/6?pretty=true) -d'{  
"title": "Test Document 6",  
"slug": "test-document-6",  
"content": "

Some content

",  
"published": "2",  
"version": "5",  
"tags": [  
{  
"name": "Cars",  
"slug": "cars",  
"type": 102,  
"test": "kikou"  
},  
{  
"name": "News",  
"slug": "news",  
"type": 103  
},  
{  
"name": "test",  
"slug": "news",  
"type": 104,  
"test": "kikou"  
}  
]  
}'  
\*

here is my query :  
_curl -XGET [http://localhost:9200/cars/documents/\_search?pretty=true](http://localhost:9200/cars/documents/_search?pretty=true) -d'{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"range": { "published": { "gt": 0 } }  
},  
{"nested": {  
"path": "tags",  
"query": {  
"filtered": {  
"filter": {  
"and": [  
{  
"term": {  
"tags.type": "104"  
}  
},{  
"term": {  
"tags.test": "kikou"  
}  
}  
]  
}  
}  
}  
}  
}  
]  
}  
}  
}  
}  
}'_

I would like to get only these fields :  
"title": "Test Document 6",  
"slug": "test-document-6",  
"content": "

Some content

",  
"published": "2",  
"version": "5",  
"tags":  
{  
"name": "test",  
"slug": "news",  
"type": 104,  
"test": "kikou"  
}

and not the whole object matching to the conditions. It sounds easy but i'm  
breaking my head on it (syntax doesn't help me ...)

Does someone have an idea ?

Regards,

Fabien

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [July 2, 2013, 11:46pm UTC](https://discuss.elastic.co/t/nested-objects-selection/12622/2 "2013-07-02T23:46:23Z")

</div>

That functionality is not yet supported:

> <https://github.com/elastic/elasticsearch/issues/3022>
>
> Add support for including the matching nested inner objects per hit element.

--  
Ivan

On Tue, Jul 2, 2013 at 10:24 AM, Fabien Chung [chung.fabien@gmail.com](mailto:chung.fabien@gmail.com)wrote:

> hello,
> 
> I would like to select only some objects in my nasted objects array.  
> Data comes from ([Search articles by tag slug · GitHub](https://gist.github.com/haswalt/a0d78e7c32ec76f03681)) :
> 
> \*curl -XPOST [http://localhost:9200/cars/documents/1?pretty=true](http://localhost:9200/cars/documents/1?pretty=true) -d'{  
> "title": "Test Document 1",  
> "slug": "test-document-1",  
> "content": "
> 
> Some content
> 
> ",  
> "published": "2",  
> "version": "2",  
> "tags": [  
> {  
> "name": "Cars",  
> "slug": "cars",  
> "type": 101  
> },  
> {  
> "name": "News",  
> "slug": "news",  
> "type": 102  
> }  
> ]  
> }'
> 
> curl -XPOST [http://localhost:9200/cars/documents/2?pretty=true](http://localhost:9200/cars/documents/2?pretty=true) -d'{  
> "title": "Test Document 2",  
> "slug": "test-document-2",  
> "content": "
> 
> Some content
> 
> ",  
> "published": "2",  
> "version": "2",  
> "tags": [  
> {  
> "name": "Cars",  
> "slug": "cars",  
> "type": 101  
> },  
> {  
> "name": "Reviews",  
> "slug": "reviews",  
> "type": 102  
> }  
> ]  
> }'
> 
> curl -XPOST [http://localhost:9200/cars/documents/3?pretty=true](http://localhost:9200/cars/documents/3?pretty=true) -d'{  
> "title": "Test Document 3",  
> "slug": "test-document-3",  
> "content": "
> 
> Some content
> 
> ",  
> "published": "2",  
> "version": "2",  
> "tags": [  
> {  
> "name": "Cars",  
> "slug": "cars",  
> "type": 101  
> },  
> {  
> "name": "Reviews",  
> "slug": "reviews",  
> "type": 102  
> }  
> ]  
> }'
> 
> curl -XPOST [http://localhost:9200/cars/documents/4?pretty=true](http://localhost:9200/cars/documents/4?pretty=true) -d'{  
> "title": "Test Document 4",  
> "slug": "test-document-4",  
> "content": "
> 
> Some content
> 
> ",  
> "published": 0,  
> "version": 2,  
> "tags": [  
> {  
> "name": "Cars",  
> "slug": "cars",  
> "type": 101  
> },  
> {  
> "name": "Reviews",  
> "slug": "reviews",  
> "type": 102  
> }  
> ]  
> }'
> 
> curl -XPOST [http://localhost:9200/cars/documents/5?pretty=true](http://localhost:9200/cars/documents/5?pretty=true) -d'{  
> "title": "Test Document 5",  
> "slug": "test-document-5",  
> "content": "
> 
> Some content
> 
> ",  
> "published": "2",  
> "version": "2",  
> "tags": [  
> {  
> "name": "Cars",  
> "slug": "cars",  
> "type": 101  
> },  
> {  
> "name": "Reviews",  
> "slug": "reviews",  
> "type": 102  
> }  
> ]  
> }'  
> curl -XPOST [http://localhost:9200/cars/documents/6?pretty=true](http://localhost:9200/cars/documents/6?pretty=true) -d'{  
> "title": "Test Document 6",  
> "slug": "test-document-6",  
> "content": "
> 
> Some content
> 
> ",  
> "published": "2",  
> "version": "5",  
> "tags": [  
> {  
> "name": "Cars",  
> "slug": "cars",  
> "type": 102,  
> "test": "kikou"  
> },  
> {  
> "name": "News",  
> "slug": "news",  
> "type": 103  
> },  
> {  
> "name": "test",  
> "slug": "news",  
> "type": 104,  
> "test": "kikou"  
> }  
> ]  
> }'  
> \*
> 
> here is my query :  
> _curl -XGET [http://localhost:9200/cars/documents/\_search?pretty=true](http://localhost:9200/cars/documents/_search?pretty=true)  
> -d'{  
> "query": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "range": { "published": { "gt": 0 } }  
> },  
> {"nested": {  
> "path": "tags",  
> "query": {  
> "filtered": {  
> "filter": {  
> "and": [  
> {  
> "term": {  
> "tags.type": "104"  
> }  
> },{  
> "term": {  
> "tags.test": "kikou"  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }'_
> 
> I would like to get only these fields :  
> "title": "Test Document 6",  
> "slug": "test-document-6",  
> "content": "
> 
> Some content
> 
> ",  
> "published": "2",  
> "version": "5",  
> "tags":  
> {  
> "name": "test",  
> "slug": "news",  
> "type": 104,  
> "test": "kikou"  
> }
> 
> and not the whole object matching to the conditions. It sounds easy but  
> i'm breaking my head on it (syntax doesn't help me ...)
> 
> Does someone have an idea ?
> 
> Regards,
> 
> Fabien
> 
> --  
> 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).

--  
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:28am UTC](https://discuss.elastic.co/t/nested-objects-selection/12622/3 "2017-07-06T02:28:32Z")

</div>


