我尝试创建一个函数,通过Elasticsearch返回事件计数。
当我运行此代码时,它首先会引发BroadcastShardOperationFailedException
,然后引发嵌套QueryParsingException
。
但是我的查询有些错误,但我不知道它可能是什么。这是我的疑问:
esclient = Elasticsearch()
countParams['body'] = {}
countParams['body']['query']= {}
countParams['body']['query']['filtered']= {}
countParams['body']['query']['filtered']['filter']= {}
countParams['body']['query']['filtered']['filter']['or']={}
toadd['term'] = {}
toadd['term']['log_device_id']= id["ID"]
countParams['body']['query']['filtered']['filter']['or']= toadd
countResponse = esclient.count(index='indexName',
doc_type='event',
body=countParams)
这只是文件的一部分,但这部分不起作用,它让我发疯。
我找不到Elasticsearch的count函数的文档。
编辑:
这里有完整的异常消息:
GET /indexName/event/_count [status:400 request:0.007s]
TransportError(400, '{"count":0,"_shards": {"total":5,"successful":0,"failed":5,"failures": [{"index":"IndexName","shard":0,"reason":"BroadcastShardOperationFailedException[[logappclient1][0] ]; nested: QueryParsingException[[indexName] [filtered] query does not support [term]]; "},{"index":"indexName","shard":1,"reason":"BroadcastShardOperationFailedException[[indexName][1] ]; nested: QueryParsingException[[indexName] [filtered] query does not support [term]]; "},{"index":"indexName","shard":2,"reason":"BroadcastShardOperationFailedException[[indexName][2] ]; nested: QueryParsingException[[indexName] [filtered] query does not support [term]]; "},{"index":"indexName","shard":3,"reason":"BroadcastShardOperationFailedException[[indexName][3] ]; nested: QueryParsingException[[indexName] [filtered] query does not support [term]]; "},{"index":"indexName","shard":4,"reason":"BroadcastShardOperationFailedException[[logappclient1][4] ]; nested: QueryParsingException[[indexName] [filtered] query does not support [term]]; "}]}}')
非常感谢您的帮助!
答案 0 :(得分:1)
试试这样:
esclient = Elasticsearch()
countParams = {
'query': {
'filtered': {
'filter': {
'or': [
{
'term': {
'log_device_id': id["ID"]
}
}
]
}
}
}
}
countResponse = esclient.count(index='indexName',
doc_type='event',
body=countParams)