# Nested fields and \_field\_names

**URL:** <https://discuss.elastic.co/t/nested-fields-and--field-names/19216>\
**Category:** Elasticsearch\
**Created:** [August 12, 2014, 3:49am UTC](https://discuss.elastic.co/t/nested-fields-and--field-names/19216 "2014-08-12T03:49:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Li](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/peter_li/32/109125_2.png) [@Peter\_Li](https://discuss.elastic.co/u/Peter_Li)\
**Post date:** [August 12, 2014, 3:49am UTC](https://discuss.elastic.co/t/nested-fields-and--field-names/19216/1 "2014-08-12T03:49:07Z")

</div>

I am trying to profile fields by counting documents with each given field.  
I am using 1.3.0 ES, so I thought I can use:

aggs: {  
docs : {  
terms : {  
field : \_field\_names,  
size : 0  
}  
}  
}

to give a count of documents with each specific field/path.

But this returns nothing for nested fields. When I use a mapping of

a : {  
type : nested,  
properties: {  
x : {...}  
y : {...}  
}  
}

for document structures like

a : [  
{ x : ..., y: ... },  
{ x : ..., y: ... }  
]

The aggregate returns nothing for x and y. Is this a bug ?

Thanks,  
Peter Li

--  
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/c535ad64-ed80-446b-9927-13a424556a1c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c535ad64-ed80-446b-9927-13a424556a1c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [August 12, 2014, 1:35pm UTC](https://discuss.elastic.co/t/nested-fields-and--field-names/19216/2 "2014-08-12T13:35:53Z")

</div>

\_field\_names tracks the field names of the current index document, so if  
you need to be in the context of your nested documents to aggregate on  
their field names. That would give something like:

GET test/\_search  
{  
"aggs": {  
"nested\_docs": {  
"nested": {  
"path": "a"  
},  
"aggs": {  
"top\_fields": {  
"terms": {  
"field": "\_field\_names",  
"size": 10  
}  
}  
}  
}  
}  
}

On Tue, Aug 12, 2014 at 5:49 AM, Peter Li [jenli.peter@gmail.com](mailto:jenli.peter@gmail.com) wrote:

> I am trying to profile fields by counting documents with each given field.  
> I am using 1.3.0 ES, so I thought I can use:
> 
> aggs: {  
> docs : {  
> terms : {  
> field : \_field\_names,  
> size : 0  
> }  
> }  
> }
> 
> to give a count of documents with each specific field/path.
> 
> But this returns nothing for nested fields. When I use a mapping of
> 
> a : {  
> type : nested,  
> properties: {  
> x : {...}  
> y : {...}  
> }  
> }
> 
> for document structures like
> 
> a : [  
> { x : ..., y: ... },  
> { x : ..., y: ... }  
> ]
> 
> The aggregate returns nothing for x and y. Is this a bug ?
> 
> Thanks,  
> Peter Li
> 
> --  
> 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/c535ad64-ed80-446b-9927-13a424556a1c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c535ad64-ed80-446b-9927-13a424556a1c%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/c535ad64-ed80-446b-9927-13a424556a1c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/c535ad64-ed80-446b-9927-13a424556a1c%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
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/CAL6Z4j6NcZrxezb%2BnEOcOQY-BCqazF3tp9oNGB130\_fh\_SooGw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j6NcZrxezb%2BnEOcOQY-BCqazF3tp9oNGB130_fh_SooGw%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:09am UTC](https://discuss.elastic.co/t/nested-fields-and--field-names/19216/3 "2017-07-06T01:09:13Z")

</div>


