Question

I have a following query and I want to change that query into PyES:



    {
      "facets": {
        "participating-org.name": {
          "terms": {
            "field": "participating-org.name"
          },
          "nested": "participating-org"
        }
      }
    }


I have searched in PyES documentation about:

class pyes.facets.TermsFacetFilter(field=None, values=None, _name=None, execution=None, **kwargs)

And I don't know how to use it plus I couldn't find any examples related to it. Hoping to see PyES guys coming out with good documentation with examples in future.

Was it helpful?

Solution

I have just found out myself:



    from pyes import *
    from pyes.facets import *

    conn = ES('localhost:9200', default_indices='org', default_types='activity')

    q2 = MatchAllQuery().search()
    q2.facet.add_term_facet('participating-org.role', nested="participating-org")


    # Displays the ES JSON query.
    print q2

    resultset = conn.search(q2)

    # To display the all resultsets.
    for r in resultset:
        print r

    # To display the facet counts.
    print resultset.facets


This code gives the above JSON Code and gives the exact count for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top