ElasticQueryElasticSearch 查询构建器
ElasticQuery 是用于 ElasticSearch 的简单查询构建器。可使用 metod 方法调用和相应的参数来生成查询、过滤和聚合对象。输出的 dict/json 可直接传递给 ES。
示例代码:
from elasticsearch import Elasticsearch from elasticquery import ElasticQuery, Filter, Query # Create a query with our ES index details q = ElasticQuery( es=Elasticsearch(), index='mapping_test', doc_type='doc_mapping' ) # Query it! q.query( Query.terms('my_field', ['my', 'terms']) ) # Aggregate it! q.aggregate( Aggregate.sum('my_agg', 'my_field') ) # Print the query, then run on ES and print it's output print q.json(indent=4) print q.get()
评论