msearch query with filter and aggregations doesn't work
See original GitHub issueHello. Is there a way to run more complex queries with filters and aggregations than in https://github.com/elastic/elasticsearch-py/issues/59? For example,
{ "size": 0,
"query": {
"match": {"search_key": "my_key_value"}
},
"filter": {
"bool": {
"must": [
{
"fquery": {
"query": {
"query_string": {
"query": "applicationType:(\"myapptype\")"
}
}
}
}
]
}
},
"aggs": {
"client": {
"terms": {
"field": "client"
}
}
}
}
If I do the following, the query doesn’t run:
es = Elasticsearch()
es.msearch(body=[{
"index": "index20150315"},
{"query": {'filter': {'bool': {'must': [{'fquery': {'query': {'query_string': {'query': 'applicationType:("myapptype")'}}}}]}}, 'query': {'match': {'search_key': 'my_key_value'}}, 'aggs': {'client': {'terms': {'field': 'client'}}}, 'size': 0}
])
The output is:
{u'responses': [{u'error': u'SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[BRYrrx8dR4i-ukxlXbuNEw][index20150315][1]: RemoteTransportException[[i-1f34c5fb][inet[/10.101.2.234:9300]][search/phase/query]]; nested: SearchParseException[[index20150315][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"filter": {"bool": {"must": [{"fquery": {"query": {"query_string": {"query": "applicationType:(\\"myapptype\\")"}}}}]}}, "query": {"match": {"search_key": "my_key_value"}}, "aggs": {"client": {"terms": {"field": "client"}}}, "size": 0}}]]]; nested: QueryParsingException[[index20150315] No query registered for [filter]]; }{[BRYrrx8dR4i-ukxlXbuNEw][index20150315][2]: RemoteTransportException[[i-1f30c5fb][inet[/10.101.2.234:9300]][search/phase/query]]; nested: SearchParseException[[index20150315][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"filter": {"bool": {"must": [{"fquery": {"query": {"query_string": {"query": "applicationType:(\\"myapptype\\")"}}}}]}}, "query": {"match": {"search_key": "my_key_value"}}, "aggs": {"client": {"terms": {"field": "client"}}}, "size": 0}}]]]; nested: QueryParsingException[[index20150315] No query registered for [filter]]; }{[No9GT_PtQh6XoOvfz5uTmw][index20150315][0]: RemoteTransportException[[i-1d30c5f9][inet[/10.101.2.237:9300]][search/phase/query]]; nested: SearchParseException[[index20150315][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"query": {"filter": {"bool": {"must": [{"fquery": {"query": {"query_string": {"query": "applicationType:(\\"myapptype\\")"}}}}]}}, "query": {"match": {"search_key": "my_key_value"}}, "aggs": {"client": {"terms": {"field": "client"}}}, "size": 0}}]]]; nested: QueryParsingException[[index20150315] No query registered for [filter]]; }]'}]}
This is yet with just one query in there though I need quite a lot of similar to be processed by msearch. Could you please provide some instructions how to form a query in this case to match to what msearch is expecting? Software versions: Python 2.6.6, elasticsearch-py 1.4.0, Elasticsearch 1.3.2.
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Elastic search query filter and aggregation is not working
1 Answer 1 ... Using your mapping and creating recommendation of type "nested". You need to use nested filter in aggregation. Using nested...
Read more >Is using "filter" inside "aggs" more efficient than "query" at the ...
Using filters to eliminate documents from search results is more efficient than using full text search and only taking into account the highest ......
Read more >$eq inside $filter does not work on array fields - MongoDB
The problem is one of the fields by which I want to perform the filter is array ( p.metadata.category ) and Mongo $eg...
Read more >Aggregate awareness | Looker - Google Cloud
Looker uses aggregate awareness logic to find the smallest, most efficient table available in your database to run a query while still ...
Read more >Bucket Aggregations - OpenSearch documentation
If the significant_terms aggregation doesn't return any result, you might have not filtered the results with a query. Alternatively, the distribution of ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This turned out to be the improperly constructed query and it should have looked like:
And everything works then.
Yes, it should speed things up quite a bit - the queries will be run in parallel in the cluster while also eliminating a lot of network traffic.