# Source filtering of nested object data

**URL:** https://discuss.elastic.co/t/source-filtering-of-nested-object-data/16324
**Category:** Elasticsearch
**Created:** [March 12, 2014, 3:59pm UTC](https://discuss.elastic.co/t/source-filtering-of-nested-object-data/16324 "2014-03-12T15:59:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ben\_Hirsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ben_hirsch/32/1558_2.png) [@Ben\_Hirsch](https://discuss.elastic.co/u/Ben_Hirsch)
#### Post date: [March 12, 2014, 3:59pm UTC](https://discuss.elastic.co/t/source-filtering-of-nested-object-data/16324/1 "2014-03-12T15:59:29Z")

</div>

Is it possible to filter the \_source of nested data conditionally?

For example, I have nested object data like this:

{  
"name" : "Thing",  
"children" :  
{  
"id": "1",  
"qty": "4"  
},  
{  
"id": "2",  
"qty": "5"  
},  
{  
"id": "3",  
"qty": "1"  
},  
{....}  
}

In some cases I will have thousands of 'children' so I don't want to return  
them all on every query. I want to be able to just return children with  
certain "id" numbers.

Is that possible?

--  
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/92f1283a-a8d9-4b2f-8e9e-32c0234c781d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92f1283a-a8d9-4b2f-8e9e-32c0234c781d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [March 12, 2014, 8:13pm UTC](https://discuss.elastic.co/t/source-filtering-of-nested-object-data/16324/2 "2014-03-12T20:13:30Z")

</div>

You could use script\_fields to generate the values you want:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

may be a bit tricky though 🙂

On 12 March 2014 16:59, Ben Hirsch [benhirsch@gmail.com](mailto:benhirsch@gmail.com) wrote:

> Is it possible to filter the \_source of nested data conditionally?
> 
> For example, I have nested object data like this:
> 
> {  
> "name" : "Thing",  
> "children" :  
> {  
> "id": "1",  
> "qty": "4"  
> },  
> {  
> "id": "2",  
> "qty": "5"  
> },  
> {  
> "id": "3",  
> "qty": "1"  
> },  
> {....}  
> }
> 
> In some cases I will have thousands of 'children' so I don't want to  
> return them all on every query. I want to be able to just return children  
> with certain "id" numbers.
> 
> Is that possible?
> 
> --  
> 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/92f1283a-a8d9-4b2f-8e9e-32c0234c781d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92f1283a-a8d9-4b2f-8e9e-32c0234c781d%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/92f1283a-a8d9-4b2f-8e9e-32c0234c781d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/92f1283a-a8d9-4b2f-8e9e-32c0234c781d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/CAPt3XKQcdMiBoAu3AhJ-UVbJJUadnELoLK0\_i-w-zV7PNegK2Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPt3XKQcdMiBoAu3AhJ-UVbJJUadnELoLK0_i-w-zV7PNegK2Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Ben\_Hirsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ben_hirsch/32/1558_2.png) [@Ben\_Hirsch](https://discuss.elastic.co/u/Ben_Hirsch)
#### Post date: [March 12, 2014, 8:55pm UTC](https://discuss.elastic.co/t/source-filtering-of-nested-object-data/16324/3 "2014-03-12T20:55:10Z")

</div>

I will know the 5-10 id's needed to be fetched at run-time. With  
script\_fields how would I access the children with those specific id's?

On Wednesday, March 12, 2014 4:13:30 PM UTC-4, Clinton Gormley wrote:

> You could use script\_fields to generate the values you want:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-script-fields.html)
> 
> may be a bit tricky though 🙂
> 
> On 12 March 2014 16:59, Ben Hirsch \<[benh...@gmail.com](mailto:benh...@gmail.com) \<javascript:\>\>wrote:
> 
> > Is it possible to filter the \_source of nested data conditionally?
> > 
> > For example, I have nested object data like this:
> > 
> > {  
> > "name" : "Thing",  
> > "children" :  
> > {  
> > "id": "1",  
> > "qty": "4"  
> > },  
> > {  
> > "id": "2",  
> > "qty": "5"  
> > },  
> > {  
> > "id": "3",  
> > "qty": "1"  
> > },  
> > {....}  
> > }
> > 
> > In some cases I will have thousands of 'children' so I don't want to  
> > return them all on every query. I want to be able to just return children  
> > with certain "id" numbers.
> > 
> > Is that possible?
> > 
> > --  
> > 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/92f1283a-a8d9-4b2f-8e9e-32c0234c781d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92f1283a-a8d9-4b2f-8e9e-32c0234c781d%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/92f1283a-a8d9-4b2f-8e9e-32c0234c781d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/92f1283a-a8d9-4b2f-8e9e-32c0234c781d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/c514a614-d255-4b9d-a4b4-976ad52bbb44%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c514a614-d255-4b9d-a4b4-976ad52bbb44%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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: [March 13, 2014, 9:09am UTC](https://discuss.elastic.co/t/source-filtering-of-nested-object-data/16324/4 "2014-03-13T09:09:41Z")

</div>

On 12 March 2014 21:55, Ben Hirsch [benhirsch@gmail.com](mailto:benhirsch@gmail.com) wrote:

> I will know the 5-10 id's needed to be fetched at run-time. With  
> script\_fields how would I access the children with those specific id's?

With script fields, you have access to the whole \_source field, so you  
would need to write a script to step through the \_source field and to  
extract the values you are interested in into a data structure (eg an array  
or hash) which you return.

--  
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/CAPt3XKR4hfa-ziykCr1nL7Rq6b8z2XsKGcNsLZ6Wn5m5svJkQg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPt3XKR4hfa-ziykCr1nL7Rq6b8z2XsKGcNsLZ6Wn5m5svJkQg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:43am UTC](https://discuss.elastic.co/t/source-filtering-of-nested-object-data/16324/5 "2017-07-06T01:43:33Z")

</div>


