# Nested field with script\_field in a terms facet

**URL:** <https://discuss.elastic.co/t/nested-field-with-script-field-in-a-terms-facet/10570>\
**Category:** Elasticsearch\
**Created:** [January 31, 2013, 9:55am UTC](https://discuss.elastic.co/t/nested-field-with-script-field-in-a-terms-facet/10570 "2013-01-31T09:55:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DH1](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@DH1](https://discuss.elastic.co/u/DH1)\
**Post date:** [January 31, 2013, 9:55am UTC](https://discuss.elastic.co/t/nested-field-with-script-field-in-a-terms-facet/10570/1 "2013-01-31T09:55:43Z")

</div>

Hi everyone.

I stumbled upon an error and I am wondering if that's normal.  
I try to run a terms facet with a script\_field that looks like this :  
"\_source.myField".  
When myField isn't nested, all's well. I get my results.  
But when it is nested, i'm getting a error saying I can't access to that  
field. Setting the nested property on the facet doesn't change anything in  
that regard.

So, is it possible to use a nested field in such a script?  
Thanks for any info !  
DH

--  
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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [January 31, 2013, 10:33am UTC](https://discuss.elastic.co/t/nested-field-with-script-field-in-a-terms-facet/10570/2 "2013-01-31T10:33:24Z")

</div>

On Thu, 2013-01-31 at 01:55 -0800, DH wrote:

> Hi everyone.
> 
> I stumbled upon an error and I am wondering if that's normal.  
> I try to run a terms facet with a script\_field that looks like this :  
> "\_source.myField".  
> When myField isn't nested, all's well. I get my results.  
> But when it is nested, i'm getting a error saying I can't access to  
> that field. Setting the nested property on the facet doesn't change  
> anything in that regard.
> 
> So, is it possible to use a nested field in such a script?

It works for me. I suggest gisting a curl recreation of the problem, so  
that we can see exactly what it is you are doing.

clint

--  
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:** ![btiernay](https://avatars.discourse-cdn.com/v4/letter/b/bb73d2/32.png) [@btiernay](https://discuss.elastic.co/u/btiernay)\
**Post date:** [August 20, 2013, 12:58am UTC](https://discuss.elastic.co/t/nested-field-with-script-field-in-a-terms-facet/10570/3 "2013-08-20T00:58:25Z")

</div>

Hey Clinton,

Please have a look at the example curl found here:

[https://groups.google.com/d/msg/elasticsearch/vrrtTam-Asc/Ioke1PWlSKEJ](https://groups.google.com/d/msg/elasticsearch/vrrtTam-Asc/Ioke1PWlSKEJ)

I too am experiencing the same thing. Any ideas what we might be doing  
wrong that you seem to be doing differently?

Thanks!

On Thursday, 31 January 2013 05:33:24 UTC-5, Clinton Gormley wrote:

> On Thu, 2013-01-31 at 01:55 -0800, DH wrote:
> 
> > Hi everyone.
> > 
> > I stumbled upon an error and I am wondering if that's normal.  
> > I try to run a terms facet with a script\_field that looks like this :  
> > "\_source.myField".  
> > When myField isn't nested, all's well. I get my results.  
> > But when it is nested, i'm getting a error saying I can't access to  
> > that field. Setting the nested property on the facet doesn't change  
> > anything in that regard.
> > 
> > So, is it possible to use a nested field in such a script?
> 
> It works for me. I suggest gisting a curl recreation of the problem, so  
> that we can see exactly what it is you are doing.
> 
> clint

--  
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:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [August 26, 2013, 9:47am UTC](https://discuss.elastic.co/t/nested-field-with-script-field-in-a-terms-facet/10570/4 "2013-08-26T09:47:43Z")

</div>

Hi Bob,

The `_source` is stored with the main (root) document and isn't accessible  
from a nested inner object (it is decoupled from the main Lucene document  
that has the \_source). What you can do is store the `chapter. paragraph.keywords` field via the mapping (store=true) and access it via  
the \_fields['chapter.paragraph.keywords'] notation in the script.

On 20 August 2013 02:58, btiernay [rtiernay@gmail.com](mailto:rtiernay@gmail.com) wrote:

> Hey Clinton,
> 
> Please have a look at the example curl found here:
> 
> [https://groups.google.com/d/msg/elasticsearch/vrrtTam-Asc/Ioke1PWlSKEJ](https://groups.google.com/d/msg/elasticsearch/vrrtTam-Asc/Ioke1PWlSKEJ)
> 
> I too am experiencing the same thing. Any ideas what we might be doing  
> wrong that you seem to be doing differently?
> 
> Thanks!
> 
> On Thursday, 31 January 2013 05:33:24 UTC-5, Clinton Gormley wrote:
> 
> > On Thu, 2013-01-31 at 01:55 -0800, DH wrote:
> > 
> > > Hi everyone.
> > > 
> > > I stumbled upon an error and I am wondering if that's normal.  
> > > I try to run a terms facet with a script\_field that looks like this :  
> > > "\_source.myField".  
> > > When myField isn't nested, all's well. I get my results.  
> > > But when it is nested, i'm getting a error saying I can't access to  
> > > that field. Setting the nested property on the facet doesn't change  
> > > anything in that regard.
> > > 
> > > So, is it possible to use a nested field in such a script?
> > 
> > It works for me. I suggest gisting a curl recreation of the problem, so  
> > that we can see exactly what it is you are doing.
> > 
> > clint
> > 
> > --  
> > 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).

--  
Met vriendelijke groet,

Martijn van Groningen

--  
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:19am UTC](https://discuss.elastic.co/t/nested-field-with-script-field-in-a-terms-facet/10570/5 "2017-07-06T02:19:49Z")

</div>


