-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Description
Elasticsearch version
6.0.0, 6.0.1
Plugins installed: []
JVM version :
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.17.10.2-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
OS version :
Ubuntu 17.10 with kernel 4.13.0-19-generic
Description of the problem including expected versus actual behavior:
Query with filter aggregation based on terms filter lookup nested below other aggregation terminates with error "query must be rewritten first". The same query executed on version 5.6.5 finishes with success.
This error is very similar to already reported and closed: #21301
The only difference is that now query fails when nested aggregation is used.
Steps to reproduce:
Recreation steps are based on those provided in issue #21301:
- create index test_posts
PUT test_posts
{
"mappings": {
"post": {
"properties": {
"mentionIDs": {
"type": "keyword"
}
}
}
}
}
- create index test_users
PUT test_users
{
"mappings": {
"user": {
"properties": {
"notifications": {
"type": "keyword"
}
}
}
}
}
- index some user
PUT test_users/user/USR|CLIENTID|1234
{
"notifications": ["abc"]
}
- insert some post
PUT test_posts/post/POST|4321
{
"mentionIDs": ["abc"]
}
- execute search (this search finishes with success - it is similar to that from Terms lookup filter in filter aggregation complains that the query is not rewritten #21301)
GET test_posts/_search
{
"aggs": {
"itemsNotify": {
"filter": {
"terms": {
"mentionIDs": {
"index": "test_users",
"type": "user",
"id": "USR|CLIENTID|1234",
"path": "notifications",
"routing": "CLIENTID"
}
}
}
}
}
}
6. This search fails with error on ES 6.0.0 and ES 6.0.1:
GET /test_posts/_search
{
"aggs": {
"facets": {
"global": {},
"aggs": {
"filteredFacets": {
"filter": {
"terms": {
"mentionIDs": {
"index": "test_users",
"type": "user",
"id": "USR|CLIENTID|1234",
"path": "notifications",
"routing": "CLIENTID"
}
}
}
}
}
}
}
}
Query result is:
{
"error": {
"root_cause": [
{
"type": "unsupported_operation_exception",
"reason": "query must be rewritten first"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "test_posts",
"node": "5ipdZJUdSqKf5gnOkwlkDg",
"reason": {
"type": "unsupported_operation_exception",
"reason": "query must be rewritten first"
}
}
]
},
"status": 500
}
Above query finishes with success on ES 5.6.5
Fragment of logs from server:
es-query-must-be-rewritten.log