gpt4 book ai didi

python-3.x - Elasticsearch QueryParsingException计数查询

转载 作者:行者123 更新时间:2023-12-03 01:55:19 25 4
gpt4 key购买 nike

我尝试创建一个函数,该函数返回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统计功能的文档。

编辑:

这里是完整的异常消息:
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]]; "}]}}')

非常感谢您的帮助!

最佳答案

尝试这样:

esclient = Elasticsearch()

countParams = {
'query': {
'filtered': {
'filter': {
'or': [
{
'term': {
'log_device_id': id["ID"]
}
}
]
}
}
}
}

countResponse = esclient.count(index='indexName',
doc_type='event',
body=countParams)

关于python-3.x - Elasticsearch QueryParsingException计数查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37154939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com