简体   繁体   English

将ElasticSearch方面查询转换为PyES

[英]Translating ElasticSearch Facets Query into PyES

I have a following query and I want to change that query into PyES: 我有以下查询,我想将该查询更改为PyES:



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

I have searched in PyES documentation about: 我在PyES文档中搜索了以下内容:

class pyes.facets.TermsFacetFilter(field=None, values=None, _name=None, execution=None, **kwargs) pyes.facets.TermsFacetFilter类(field = None,values = None,_name = None,execute = 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. 希望以后PyES的家伙能提供很好的文档和示例。

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. 该代码提供了上述JSON代码,并为我提供了准确的计数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM