Reputation: 182
I try to create a function that returns me the count of events with Elasticsearch.
When I run this code it raises at first a BroadcastShardOperationFailedException
and then a nested QueryParsingException
.
But somethings wrong with my query but I don't get it what it could be. Here's my query:
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)
That's only a part of the file but this part wont work and it drives me crazy.
I don't find a documentation to the count func of Elasticsearch.
Edit:
Here the full exception message:
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]]; "}]}}')
Thanks a lot for help!
Upvotes: 0
Views: 240
Reputation: 217274
Try like this:
esclient = Elasticsearch()
countParams = {
'query': {
'filtered': {
'filter': {
'or': [
{
'term': {
'log_device_id': id["ID"]
}
}
]
}
}
}
}
countResponse = esclient.count(index='indexName',
doc_type='event',
body=countParams)
Upvotes: 1