Skip to content


Other facet information #191

eire1130 opened this Issue · 5 comments

3 participants


Lately I've had a need for the other meta information returned in the facet stanza.

Currently, elasticutils only returns the terms and facet counts and not the other attributes from the facet_counts() method.

The terms facets looks like this:

{u'facetable_thing': [{u'count': 247267, u'term': 6}, {u'count': 23315, u'term': 7}, {u'count': 12294, u'term': 3}, {u'count': 9366, u'term': 5}, {u'count': 8568, u'term': 2}, {u'count': 5702, u'term': 22}, {u'count': 3128, u'term': 16}, {u'count': 1768, u'term': 18}, {u'count': 1730, u'term': 21}, {u'count': 1154, u'term': 12}]}

Specifically, in the terms facet, the attributes returned are:

  • _type:facet_type
  • missing:int
  • total:int
  • other:int
  • terms:[]

Specifically, the "other" is what is most useful. For example, let's save the above results query looks like this:

  "facets": {
    "facetable_thing": {
      "terms": {
        "field": "facetable_thing",
        "size": 10

And there could be fifty such facets, but you only want to show the first ten on the UI, you would do the query as above, but let's say you wanted to expand that out in increments of ten, you could do that easily enough, except when you hit exactly fifty. Then you will have a 'see more' button that doesn't do anything when pressed.

Grabbing the "other" makes this trivial. Of course, there are other ways of doing this too, like returning 11 facets and test to see if an 11th is actually there, del the 11th and send that off to the UI, but why do all that error prone hacking when you can just look at "other"?


I think there's a few ways to go here.

  1. return facetable_thing_other and facetable_things_missing in the current result set.

  2. create an iterable "FacetResult" object.

Something like:

class FacetResult(object):
    def __init__(*args, **kwargs):
      self.missing = missing
      self.other = other = data
    def __iter__(self):
        return self
    def next(self): #__next__ in python3k
        if self.i<len(
            self.i += 1         
            raise StopIteration

The idea here is it wouldn't break anyones code if they are expecting an iterable in their current results.

I'd be open to other suggestions as well.

I can work on this, I just want to know what direction makes the most for the project.


I went ahead with it and made a commit (but not a pull request) if you like the api, i'll send a pull request.


It's passing all tests.

Mozilla member

Hi! I apologize that it took me two months and an email to reply. I'm crazy busy right now and while I've been keeping an eye on the Pull Request queue, I haven't looked at issues in a while.

Until now, I hadn't looked at this at all. My very very quick skim suggests it looks good. I'll try to look at it more closely and give you my thoughts on the API in the next week.


Thanks for taking a look at it and no worries!

It sounds like you like it in concept, so I'm going to go ahead and put together some documentation.

My only other thought is elasticsearch 1.0 compatibility with aggregations coming. Maybe @HonzaKral can shed some light there?


With 1.0 facets are still not going anywhere for a while so we have plenty time to figure out how to integrate with it and provide some nice abstractions.

@willkg willkg added this to the 0.10 milestone
@willkg willkg added a commit that closed this issue
@eire1130 eire1130 added FacetResults object
Fixes #191
@willkg willkg closed this in aa050f9
@willkg willkg modified the milestone: 0.9, 0.10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.