Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child query error when using _score script in nested aggregation #35985

Closed
worldsayshi opened this issue Nov 28, 2018 · 4 comments · Fixed by #36019
Closed

Child query error when using _score script in nested aggregation #35985

worldsayshi opened this issue Nov 28, 2018 · 4 comments · Fixed by #36019

Comments

@worldsayshi
Copy link

worldsayshi commented Nov 28, 2018

Please see my self contained reproduction repository here.

I get an error when trying to run a query that seems reasonable to me. I'm able to avoid the error by setting size to 1.

Elasticsearch version: 6.4.2, 6.5.1 and 7.0.0-alpha1

Plugins installed: None

JVM version: I'm running the official elastic docker image

OS version: I'm running the official elastic docker image

Description of the problem including expected versus actual behavior:

Steps to reproduce:

Please see my self contained reproduction repository here. It contains all the steps.

Here's the query used in the reproduction:

{
  "size": 0,
  "query": {
    "nested": {
      "query": {
        "match": {
          "dimension_filter_nested.name": {
            "query": "Meine produktkategorie wellendurchmesser"
          }
        }
      },
      "path": "dimension_filter_nested"
    }
  },
  "aggregations": {
    "my-agg-1": {
      "filter": {
        "terms": {
          "taxonomy.raw": ["/Meine produktkategorie"]
        }
      },
      "aggregations": {
        "my-agg-2": {
          "nested": {
            "path": "dimension_filter_nested"
          },
          "aggregations": {
            "my-agg-3": {
              "terms": {
                "field": "dimension_filter_nested.name.raw",
                "size": 10,
                "order": [{
                  "max_score": "desc"
                }, {
                  "_key": "asc"
                }]
              },
              "aggregations": {
                "max_score": {
                  "max": {
                    "script": {
                      "source": "_score",
                      "lang": "painless"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

The error (7.0.0-alpha1):

{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "runtime error",
        "script_stack" : [
          "org.apache.lucene.search.join.ToParentBlockJoinQuery$BlockJoinScorer.setScoreAndFreq(ToParentBlockJoinQuery.java:349)",
          "org.apache.lucene.search.join.ToParentBlockJoinQuery$BlockJoinScorer.score(ToParentBlockJoinQuery.java:309)",
          "org.apache.lucene.search.ConjunctionScorer.score(ConjunctionScorer.java:59)",
          "org.apache.lucene.search.FilterScorable.score(FilterScorable.java:46)",
          "org.elasticsearch.script.AggregationScript.get_score(AggregationScript.java:124)",
          "<<< unknown portion of script >>>"
        ],
        "script" : "_score",
        "lang" : "painless"
      }
    ],
    "type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "integration_test_index_de",
        "node" : "VmWbmOc3SbSLmb8LNQml0A",
        "reason" : {
          "type" : "script_exception",
          "reason" : "runtime error",
          "script_stack" : [
            "org.apache.lucene.search.join.ToParentBlockJoinQuery$BlockJoinScorer.setScoreAndFreq(ToParentBlockJoinQuery.java:349)",
            "org.apache.lucene.search.join.ToParentBlockJoinQuery$BlockJoinScorer.score(ToParentBlockJoinQuery.java:309)",
            "org.apache.lucene.search.ConjunctionScorer.score(ConjunctionScorer.java:59)",
            "org.apache.lucene.search.FilterScorable.score(FilterScorable.java:46)",
            "org.elasticsearch.script.AggregationScript.get_score(AggregationScript.java:124)",
            "<<< unknown portion of script >>>"
          ],
          "script" : "_score",
          "lang" : "painless",
          "caused_by" : {
            "type" : "illegal_state_exception",
            "reason" : "Child query must not match same docs with parent filter. Combine them as must clauses (+) to find a problem doc. docId=2147483647, class org.apache.lucene.search.TermScorer"
          }
        }
      }
    ]
  },
  "status" : 400
}
@worldsayshi
Copy link
Author

This issue looks related: #28478

@cbuescher cbuescher added :Analytics/Aggregations Aggregations :Search/Search Search-related issues that do not fall into other categories :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache labels Nov 28, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@cbuescher cbuescher added >bug and removed :Search/Search Search-related issues that do not fall into other categories labels Nov 28, 2018
@colings86 colings86 removed the :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache label Nov 28, 2018
jimczi added a commit to jimczi/elasticsearch that referenced this issue Nov 28, 2018
The nested agg can defer the collection of children if it is nested
under another aggregation. In such case accessing the score in the children
aggregation throws an error because the scorer has already advanced to the next
parent. This change fixes this error by caching the score of the parent in the
nested aggregation. Children aggregations that work on nested documents will be
able to access the _score. Also note that the _score in this case is always the
parent's score, there is no way to retrieve the score of a nested docs in aggregations.

Closes elastic#35985
Closes elastic#34555
jimczi added a commit that referenced this issue Nov 29, 2018
The nested agg can defer the collection of children if it is nested
under another aggregation. In such case accessing the score in the children
aggregation throws an error because the scorer has already advanced to the next
parent. This change fixes this error by caching the score of the parent in the
nested aggregation. Children aggregations that work on nested documents will be
able to access the _score. Also note that the _score in this case is always the
parent's score, there is no way to retrieve the score of a nested docs in aggregations.

Closes #35985
Closes #34555
jimczi added a commit that referenced this issue Nov 29, 2018
The nested agg can defer the collection of children if it is nested
under another aggregation. In such case accessing the score in the children
aggregation throws an error because the scorer has already advanced to the next
parent. This change fixes this error by caching the score of the parent in the
nested aggregation. Children aggregations that work on nested documents will be
able to access the _score. Also note that the _score in this case is always the
parent's score, there is no way to retrieve the score of a nested docs in aggregations.

Closes #35985
Closes #34555
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants