# Nested objects selection

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

<div class="post-metadata">

**Author:** ![Tangred](https://avatars.discourse-cdn.com/v4/letter/t/b2d939/32.png) [@Tangred](https://discuss.elastic.co/u/Tangred)\
**Post date:** [July 2, 2013, 3:19pm UTC](https://discuss.elastic.co/t/nested-objects-selection/12620/1 "2013-07-02T15:19:52Z")

</div>

hello,

I would like to select only some objects in my nasted objects 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

---

<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/12620/2 "2017-07-06T02:28:38Z")

</div>


