运行此代码
try:
connections.create_connection(hosts=[ES_IP], timeout=ES_TIMEOUT, http_auth=(USERNAME, PASSWORD))
print "Connected to elasticsearch node "+ES_IP
#logging.info("Connected to elasticsearch node "+ES_IP)
except:
print "Connection refused by elasticsearch node "+ES_IP
#logging.error("Connection refused by elasticsearch node "+ES_IP)
return -1
else:
s=Search(index = "*-indices-alias")
a = A('matrix_stats',field=['ERABESTABADDATTNBRQCI1','ERABESTABADDATTNBRQCI6'])
s.aggs.bucket('statistics',a)
pprint(str(s.to_dict()))
我收到此错误
Traceback (most recent call last):
File "elastic_query.py", line 45, in <module>
run_agg_dsl_query()
File "elastic_query.py", line 41, in run_agg_dsl_query
a = A('matrix_stats',field=
['ERABESTABADDATTNBRQCI1','ERABESTABADDATTNBRQCI6'])
File "/usr/local/lib/python2.7/dist-packages/elasticsearch_dsl/aggs.py", line 42, in A
return Agg.get_dsl_class(name_or_agg)(**params)
File "/usr/local/lib/python2.7/dist-packages/elasticsearch_dsl/utils.py", line 216, in get_dsl_class
raise UnknownDslObject('DSL class `%s` does not exist in %s.' % (name, cls._type_name))
elasticsearch_dsl.exceptions.UnknownDslObject: DSL class `matrix_stats` does not exist in agg.
如果我将“ matrix_stats”替换为“ terms”,查询将生成为
"{'query': {'match_all': {}}, 'aggs': {'statistics': {'terms': {'field': ['ERABESTABADDATTNBRQCI1', 'ERABESTABADDATTNBRQCI6']}}}}"
但我希望查询生成为
"{'query': {'match_all': {}}, 'aggs': {'statistics': {'matrix_stats': {'field': ['ERABESTABADDATTNBRQCI1', 'ERABESTABADDATTNBRQCI6']}}}}"
elasticsearch-DSL库当前不支持matrix_stats吗? 如果是,是否可以期望将来增加矩阵聚合? 如果没有的话,那将是我不熟悉的东西。
感谢您的帮助。 谢谢,
答案 0 :(得分:1)
dsl
尚不支持此聚合,很抱歉。要使其可用,您始终可以通过以下方式自行定义:
from elasticsearch_dsl.aggs import Agg
class MatrixStats(Agg):
name = 'matrix_stats'
然后它应该工作。