# Search query nested fields

**URL:** <https://discuss.elastic.co/t/search-query-nested-fields/112436>\
**Category:** Elasticsearch\
**Created:** [December 19, 2017, 12:56pm UTC](https://discuss.elastic.co/t/search-query-nested-fields/112436 "2017-12-19T12:56:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![xavi23](https://avatars.discourse-cdn.com/v4/letter/x/db5fbb/32.png) [@xavi23](https://discuss.elastic.co/u/xavi23)\
**Post date:** [December 19, 2017, 12:56pm UTC](https://discuss.elastic.co/t/search-query-nested-fields/112436/1 "2017-12-19T12:56:01Z")

</div>

Hello,

I create an index with nested fields, and I load many JSON documents in this index.

When I try to search an especific field inside nested filed, always elasticsearch return the all JSON.

I need that ES return me only the field that I try to filter.

My index is this:

{  
"nested\_v3": {  
"aliases": {},  
"mappings": {  
"nested\_v3": {  
"properties": {  
"episodio": {  
"type": "nested",  
"properties": {  
"codi\_episodi": {  
"type": "integer"  
},  
"diagnostic": {  
"type": "nested",  
"properties": {  
"codi": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword"  
}  
}  
},  
"descripcio": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword"  
}  
}  
}  
}  
},  
"tx": {  
"type": "nested",  
"properties": {  
"obx": {  
"type": "nested",  
"properties": {  
"obx\_descripcion": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword"  
}  
}  
},  
"obx\_valor": {  
"type": "integer",  
"fields": {  
"raw": {  
"type": "keyword"  
}  
}  
},  
"valor": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword"  
}  
}  
}  
}  
},  
"tipotx": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword"  
}  
}  
},  
"valor\_tx": {  
"type": "integer",  
"fields": {  
"raw": {  
"type": "keyword"  
}  
}  
}  
}  
}  
}  
},  
"nhc": {  
"type": "integer"  
},  
"product": {  
"properties": {  
"categories": {  
"properties": {  
"level1": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword"  
}  
}  
},  
"level2": {  
"type": "text",  
"fields": {  
"raw": {  
"type": "keyword"  
}  
}  
}  
}  
}  
}  
}  
}  
}  
},  
"settings": {  
"index": {  
"creation\_date": "1513593412598",  
"number\_of\_shards": "5",  
"number\_of\_replicas": "1",  
"uuid": "SlAvr3W3QW6HD1ejcvrBzg",  
"version": {  
"created": "5030299"  
},  
"provided\_name": "nested\_v3"  
}  
}  
}  
}

==\> My document is this:

{  
"\_index": "nested\_v3",  
"\_type": "nested\_v3",  
"\_id": "9999999",  
"\_version": 1,  
"found": true,  
"\_source": {  
"nhc": 9999999,  
"product": [  
{  
"categories.level1": "Drama",  
"categories.level2": "Thriller"  
}  
],  
"episodio": [  
{  
"codi\_episodi": 4444,  
"tx": [  
{  
"valor\_tx": 83332,  
"tipotx": "General",  
"obx": [  
{  
"obx\_valor": "10",  
"obx\_descripcion": "Bon estat general",  
"valor": "S"  
},  
{  
"obx\_valor": "11",  
"obx\_descripcion": "Bon estat general",  
"valor": "S"  
}  
]  
},  
{  
"valor\_tx": 5555,  
"tipotx": "Antropometria",  
"obx": [  
{  
"obx\_valor": "5",  
"obx\_descripcion": "Peso",  
"valor": "80"  
},  
{  
"obx\_valor": "90",  
"obx\_descripcion": "Altura",  
"valor": "195"  
}  
]  
}  
],  
"diagnostic": [  
{  
"codi": "55",  
"descripcio": "Acantosis"  
},  
{  
"codi": "99",  
"descripcio": "Faringuitis"  
}  
]  
},  
{  
"codi\_episodi": 1111111,  
"tx": [  
{  
"valor\_tx": 83337772,  
"tipotx": "General\_episodi2",  
"obx": [  
{  
"obx\_valor": "10",  
"obx\_descripcion": "Bon estat general\_episodi2",  
"valor": "S\_episodi2"  
},  
{  
"obx\_valor": "11",  
"obx\_descripcion": "Bon estat general\_episodi2",  
"valor": "S\_episodi2"  
}  
]  
},  
{  
"valor\_tx": 988888888,  
"tipotx": "Antropometria\_episodi2",  
"obx": [  
{  
"obx\_valor": "5",  
"obx\_descripcion": "Peso\_episodi2",  
"valor": "80"  
},  
{  
"obx\_valor": "90",  
"obx\_descripcion": "Altura\_episodi2",  
"valor": "195"  
}  
]  
}  
],  
"diagnostic": [  
{  
"codi": "55",  
"descripcio": "Artrosis\_episodi2"  
},  
{  
"codi": "99",  
"descripcio": "Faringuitis Aguda\_episodi2"  
}  
]  
}  
]  
}  
}

My query is this:

GET /nested\_v3/\_search  
{  
"query": {  
"bool": {  
"must": [  
{  
"nested": {  
"path": "episodio.tx.obx",  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"episodio.tx.obx.obx\_descripcion.raw": "Peso"  
}  
}  
]  
}  
}  
}  
}  
]  
}}}

---

<div class="post-metadata">

**Author:** ![Mike.Barretta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike.barretta/32/16688_2.png) [@Mike.Barretta](https://discuss.elastic.co/u/Mike.Barretta)\
**Post date:** [December 20, 2017, 5:31pm UTC](https://discuss.elastic.co/t/search-query-nested-fields/112436/2 "2017-12-20T17:31:53Z")

</div>

@xavi23 You have a couple of ways to customize the response you get from an ES query.

- [Response Filtering](https://www.elastic.co/guide/en/elasticsearch/reference/master/common-options.html#common-options-response-filtering) can be used to select or remove parts of the response
- [Source Filtering](https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-get.html#get-source-filtering) can be used to select or remove parts of the indexed documents (the `_source` metadata field) that are included in the response

---

<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:** [January 17, 2018, 5:32pm UTC](https://discuss.elastic.co/t/search-query-nested-fields/112436/3 "2018-01-17T17:32:21Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
