# Facet document fields themselves, rather than their values

**URL:** <https://discuss.elastic.co/t/facet-document-fields-themselves-rather-than-their-values/12368>\
**Category:** Elasticsearch\
**Created:** [June 12, 2013, 6:06am UTC](https://discuss.elastic.co/t/facet-document-fields-themselves-rather-than-their-values/12368 "2013-06-12T06:06:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allan\_Johns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/allan_johns/32/2387_2.png) [@Allan\_Johns](https://discuss.elastic.co/u/Allan_Johns)\
**Post date:** [June 12, 2013, 6:06am UTC](https://discuss.elastic.co/t/facet-document-fields-themselves-rather-than-their-values/12368/1 "2013-06-12T06:06:58Z")

</div>

Hi,

Given a query, I need to get a list of the fields that exist in the  
matching documents.

To illustrate: let's say I have a set of documents with two fields - 'city'  
and 'temperature'. I can get a faceted view by city like so:

{"facets": {"city\_facet" : {"terms": {"field" : "city"}}}}  
results in:  
{  
"term" : "sydney",  
"count" : 1335  
}, {  
"term" : "London",  
"count" : 1333  
}, {  
"term" : "SanFran",  
"count" : 1325  
}... etc

But, what I would like is for some way to facet on the fields themselves,  
ie something like so:

{"facets": {"field\_facet" : {"terms": {"field" : "?FIELD??"}}}}  
results in:  
{  
"field" : "temperature",  
"count" : 2050  
}, {  
"field" : "city",  
"count" : 2104  
}

Is this possible, or does someone have a good suggestion for how I might  
fake it?

Thanks  
A

--  
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:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [June 12, 2013, 6:29am UTC](https://discuss.elastic.co/t/facet-document-fields-themselves-rather-than-their-values/12368/2 "2013-06-12T06:29:58Z")

</div>

Hey,

if I got your requirement right, you want to count for documents, which  
have a certain field set? Then you might not need faceting for that.  
What about a count request using an exists filter? One count request for  
each field you want to count, or one if you want to combine.

If I got your requirement wrong, please elaborate and we try to get it  
right.

--Alex

On Wed, Jun 12, 2013 at 8:06 AM, Allan Johns [nerdvegas@gmail.com](mailto:nerdvegas@gmail.com) wrote:

> Hi,
> 
> Given a query, I need to get a list of the fields that exist in the  
> matching documents.
> 
> To illustrate: let's say I have a set of documents with two fields -  
> 'city' and 'temperature'. I can get a faceted view by city like so:
> 
> {"facets": {"city\_facet" : {"terms": {"field" : "city"}}}}  
> results in:  
> {  
> "term" : "sydney",  
> "count" : 1335  
> }, {  
> "term" : "London",  
> "count" : 1333  
> }, {  
> "term" : "SanFran",  
> "count" : 1325  
> }... etc
> 
> But, what I would like is for some way to facet on the fields themselves,  
> ie something like so:
> 
> {"facets": {"field\_facet" : {"terms": {"field" : "?FIELD??"}}}}  
> results in:  
> {  
> "field" : "temperature",  
> "count" : 2050  
> }, {  
> "field" : "city",  
> "count" : 2104  
> }
> 
> Is this possible, or does someone have a good suggestion for how I might  
> fake it?
> 
> Thanks  
> A
> 
> --  
> 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).

--  
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:** ![Allan\_Johns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/allan_johns/32/2387_2.png) [@Allan\_Johns](https://discuss.elastic.co/u/Allan_Johns)\
**Post date:** [June 12, 2013, 6:56am UTC](https://discuss.elastic.co/t/facet-document-fields-themselves-rather-than-their-values/12368/3 "2013-06-12T06:56:18Z")

</div>

No that isn't what I want.

Given an arbitrary query, I want a list of the fields that exist in any of  
the matching documents.

So, let's say a query results in two matching documents:  
{"foo":"bah", "eek":"true"},  
{"foo":"fah", "priority":12}

I want to get the result ["foo", "eek", "priority"].

hth  
A

On Wed, Jun 12, 2013 at 4:29 PM, Alexander Reelsen [alr@spinscale.de](mailto:alr@spinscale.de) wrote:

> Hey,
> 
> if I got your requirement right, you want to count for documents, which  
> have a certain field set? Then you might not need faceting for that.  
> What about a count request using an exists filter? One count request for  
> each field you want to count, or one if you want to combine.
> 
> If I got your requirement wrong, please elaborate and we try to get it  
> right.
> 
> --Alex
> 
> On Wed, Jun 12, 2013 at 8:06 AM, Allan Johns [nerdvegas@gmail.com](mailto:nerdvegas@gmail.com) wrote:
> 
> > Hi,
> > 
> > Given a query, I need to get a list of the fields that exist in the  
> > matching documents.
> > 
> > To illustrate: let's say I have a set of documents with two fields -  
> > 'city' and 'temperature'. I can get a faceted view by city like so:
> > 
> > {"facets": {"city\_facet" : {"terms": {"field" : "city"}}}}  
> > results in:  
> > {  
> > "term" : "sydney",  
> > "count" : 1335  
> > }, {  
> > "term" : "London",  
> > "count" : 1333  
> > }, {  
> > "term" : "SanFran",  
> > "count" : 1325  
> > }... etc
> > 
> > But, what I would like is for some way to facet on the fields themselves,  
> > ie something like so:
> > 
> > {"facets": {"field\_facet" : {"terms": {"field" : "?FIELD??"}}}}  
> > results in:  
> > {  
> > "field" : "temperature",  
> > "count" : 2050  
> > }, {  
> > "field" : "city",  
> > "count" : 2104  
> > }
> > 
> > Is this possible, or does someone have a good suggestion for how I might  
> > fake it?
> > 
> > Thanks  
> > A
> > 
> > --  
> > 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).
> 
> --  
> 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).

--  
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:31am UTC](https://discuss.elastic.co/t/facet-document-fields-themselves-rather-than-their-values/12368/4 "2017-07-06T02:31:42Z")

</div>


