elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
1.21k stars 24.85k forks source link

Rescorer is ignored #31429

Closed krueger closed 6 years ago

krueger commented 6 years ago

Describe the feature:

Elasticsearch version (bin/elasticsearch --version): 5.2.2, 5.6.8

Plugins installed: []

JVM version (java -version): 1.8

OS version (uname -a if on a Unix-like system): Mac OS X, Linux

Description of the problem including expected versus actual behavior:

Value in field score is not the same as in explanation

{
    "took": 52,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 150,
        "max_score": null,
        "hits": [
            {
                "_shard": "[4374ef463c8cb7f0013c967ea77446f5][4]",
                "_node": "rmdGJduJQo2aHRWMq5Xkyw",
                "_index": "4374ef463c8cb7f0013c967ea77446f5",
                "_type": "text",
                "_id": "1huzxhz8wdcty",
                "_score": 2,
                "fields": {
                    ...
                },
                "highlight": {
                    ...
                },
                "sort": [
                    2,
                    1525781978000,
                    1525781978000
                ],
                "_explanation": {
                    "value": 170.17645,
                    "description": "sum of:",
                    "details": [

The behavior is not the same as in issue #28725. This time the score value is wrong for values inside the rescorer window.

Steps to reproduce:

Provide logs (if relevant):

Complete explanation:

"_explanation": {
                    "value": 170.17645,
                    "description": "sum of:",
                    "details": [
                        {
                            "value": 166.47151,
                            "description": "product of:",
                            "details": [
                                {
                                    "value": 166.47151,
                                    "description": "sum of:",
                                    "details": [
                                        {
                                            "value": 18.274069,
                                            "description": "product of:",
                                            "details": [
                                                {
                                                    "value": 18.274069,
                                                    "description": "sum of:",
                                                    "details": [
                                                        {
                                                            "value": 2,
                                                            "description": "product of:",
                                                            "details": [
                                                                {
                                                                    "value": 2,
                                                                    "description": "sum of:",
                                                                    "details": [
                                                                        {
                                                                            "value": 2,
                                                                            "description": "sum of:",
                                                                            "details": [
                                                                                {
                                                                                    "value": 1,
                                                                                    "description": "sum of:",
                                                                                    "details": [
                                                                                        {
                                                                                            "value": 0,
                                                                                            "description": "Score based on 1 child docs in range from 4 to 4, best match:",
                                                                                            "details": [
                                                                                                {
                                                                                                    "value": 6.4246893,
                                                                                                    "description": "sum of:",
                                                                                                    "details": [
                                                                                                        {
                                                                                                            "value": 6.4246893,
                                                                                                            "description": "sum of:",
                                                                                                            "details": [
                                                                                                                {
                                                                                                                    "value": 1,
                                                                                                                    "description": "ConstantScore(+ConstantScore(elements.aclgroups:1hbgiyci15kqf elements.aclgroups:1hbiqxefjx1t2 elements.aclgroups:4374ef463c8cb7f0013c967ea78846f9 elements.aclgroups:4374ef463c8cb7f0013c967ea78e46fa elements.aclgroups:4374ef463c8cb7f0013c967ea7a946fd elements.aclgroups:4374ef463c8cb7f0013c967ea7c54700 elements.aclgroups:4374ef49462a4bdf014638f1949349ba elements.aclgroups:4374ef49462a4bdf014638f2cc3e49d3 elements.aclgroups:4374ef49462a4bdf014638f3e1f849ea elements.aclgroups:4374ef49462a4bdf014638f55f2a4a0b elements.aclgroups:4374ef4947365a970147d95ba46e7afc elements.aclgroups:DUMMY_GROUP_ID elements.aclgroups:ubguhplma88o) +elements.hidden:F +((elements.approval_status:APPROVED (-ConstantScore(_field_names:elements.approval_status) +*:*))~1) +(+elements.valid_from:[-9223372036854775808 TO 9223372036854775807] +elements.valid_to:[1529405750520 TO 9223372036854775807])), product of:",
                                                                                                                    "details": [
                                                                                                                        {
                                                                                                                            "value": 1,
                                                                                                                            "description": "boost",
                                                                                                                            "details": []
                                                                                                                        },
                                                                                                                        {
                                                                                                                            "value": 1,
                                                                                                                            "description": "queryNorm",
                                                                                                                            "details": []
                                                                                                                        }
                                                                                                                    ]
                                                                                                                },
                                                                                                                {
                                                                                                                    "value": 5.4246893,
                                                                                                                    "description": "max of:",
                                                                                                                    "details": [
                                                                                                                        {
                                                                                                                            "value": 5.4246893,
                                                                                                                            "description": "weight(elements.content.search:goz in 4) [PerFieldSimilarity], result of:",
                                                                                                                            "details": [
                                                                                                                                {
                                                                                                                                    "value": 5.4246893,
                                                                                                                                    "description": "score(doc=4,freq=1.0 = termFreq=1.0\n), product of:",
                                                                                                                                    "details": [
                                                                                                                                        {
                                                                                                                                            "value": 3.2142298,
                                                                                                                                            "description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
                                                                                                                                            "details": [
                                                                                                                                                {
                                                                                                                                                    "value": 116,
                                                                                                                                                    "description": "docFreq",
                                                                                                                                                    "details": []
                                                                                                                                                },
                                                                                                                                                {
                                                                                                                                                    "value": 2898,
                                                                                                                                                    "description": "docCount",
                                                                                                                                                    "details": []
                                                                                                                                                }
                                                                                                                                            ]
                                                                                                                                        },
                                                                                                                                        {
                                                                                                                                            "value": 1.6877105,
                                                                                                                                            "description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
                                                                                                                                            "details": [
                                                                                                                                                {
                                                                                                                                                    "value": 1,
                                                                                                                                                    "description": "termFreq=1.0",
                                                                                                                                                    "details": []
                                                                                                                                                },
                                                                                                                                                {
                                                                                                                                                    "value": 1.2,
                                                                                                                                                    "description": "parameter k1",
                                                                                                                                                    "details": []
                                                                                                                                                },
                                                                                                                                                {
                                                                                                                                                    "value": 0.75,
                                                                                                                                                    "description": "parameter b",
                                                                                                                                                    "details": []
                                                                                                                                                },
                                                                                                                                                {
                                                                                                                                                    "value": 1807.3713,
                                                                                                                                                    "description": "avgFieldLength",
                                                                                                                                                    "details": []
                                                                                                                                                },
                                                                                                                                                {
                                                                                                                                                    "value": 7.111111,
                                                                                                                                                    "description": "fieldLength",
                                                                                                                                                    "details": []
                                                                                                                                                }
                                                                                                                                            ]
                                                                                                                                        }
                                                                                                                                    ]
                                                                                                                                }
                                                                                                                            ]
                                                                                                                        }
                                                                                                                    ]
                                                                                                                }
                                                                                                            ]
                                                                                                        },
                                                                                                        {
                                                                                                            "value": 0,
                                                                                                            "description": "match on required clause, product of:",
                                                                                                            "details": [
                                                                                                                {
                                                                                                                    "value": 0,
                                                                                                                    "description": "# clause",
                                                                                                                    "details": []
                                                                                                                },
                                                                                                                {
                                                                                                                    "value": 1,
                                                                                                                    "description": "_type:__elements, product of:",
                                                                                                                    "details": [
                                                                                                                        {
                                                                                                                            "value": 1,
                                                                                                                            "description": "boost",
                                                                                                                            "details": []
                                                                                                                        },
                                                                                                                        {
                                                                                                                            "value": 1,
                                                                                                                            "description": "queryNorm",
                                                                                                                            "details": []
                                                                                                                        }
                                                                                                                    ]
                                                                                                                }
                                                                                                            ]
                                                                                                        }
                                                                                                    ]
                                                                                                }
                                                                                            ]
                                                                                        },
                                                                                        {
                                                                                            "value": 1,
                                                                                            "description": "sum of:",
                                                                                            "details": [
                                                                                                {
                                                                                                    "value": 1,
                                                                                                    "description": "ConstantScore((aclusers:4374ef463c8cb7f0013c967ea7cc4701 (+resource:approval resource:branch resource:cancellation resource:contact resource:dialog resource:dictionary resource:document resource:eop resource:external resource:message resource:metadata resource:motd resource:note resource:question resource:realm resource:report resource:role resource:search resource:submission resource:team resource:text resource:texttemplate resource:theme resource:tree resource:user resource:usergroup resource:version +ConstantScore(aclwritegroups:1hbgiyci15kqf aclwritegroups:1hbiqxefjx1t2 aclwritegroups:4374ef463c8cb7f0013c967ea78846f9 aclwritegroups:4374ef463c8cb7f0013c967ea78e46fa aclwritegroups:4374ef463c8cb7f0013c967ea7a946fd aclwritegroups:4374ef463c8cb7f0013c967ea7c54700 aclwritegroups:4374ef49462a4bdf014638f1949349ba aclwritegroups:4374ef49462a4bdf014638f2cc3e49d3 aclwritegroups:4374ef49462a4bdf014638f3e1f849ea aclwritegroups:4374ef49462a4bdf014638f55f2a4a0b aclwritegroups:4374ef4947365a970147d95ba46e7afc aclwritegroups:DUMMY_GROUP_ID aclwritegroups:ubguhplma88o)))~1), product of:",
                                                                                                    "details": [
                                                                                                        {
                                                                                                            "value": 1,
                                                                                                            "description": "boost",
                                                                                                            "details": []
                                                                                                        },
                                                                                                        {
                                                                                                            "value": 1,
                                                                                                            "description": "queryNorm",
                                                                                                            "details": []
                                                                                                        }
                                                                                                    ]
                                                                                                },
                                                                                                {
                                                                                                    "value": 0,
                                                                                                    "description": "Score based on 1 child docs in range from 4 to 4, best match:",
                                                                                                    "details": [
                                                                                                        {
                                                                                                            "value": 5.4246893,
                                                                                                            "description": "sum of:",
                                                                                                            "details": [
                                                                                                                {
                                                                                                                    "value": 5.4246893,
                                                                                                                    "description": "max of:",
                                                                                                                    "details": [
                                                                                                                        {
                                                                                                                            "value": 5.4246893,
                                                                                                                            "description": "weight(elements.content.search:goz in 4) [PerFieldSimilarity], result of:",
                                                                                                                            "details": [
                                                                                                                                {
                                                                                                                                    "value": 5.4246893,
                                                                                                                                    "description": "score(doc=4,freq=1.0 = termFreq=1.0\n), product of:",
                                                                                                                                    "details": [
                                                                                                                                        {
                                                                                                                                            "value": 3.2142298,
                                                                                                                                            "description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
                                                                                                                                            "details": [
                                                                                                                                                {
                                                                                                                                                    "value": 116,
                                                                                                                                                    "description": "docFreq",
                                                                                                                                                    "details": []
                                                                                                                                                },
                                                                                                                                                {
                                                                                                                                                    "value": 2898,
                                                                                                                                                    "description": "docCount",
                                                                                                                                                    "details": []
                                                                                                                                                }
                                                                                                                                            ]
                                                                                                                                        },
                                                                                                                                        {
                                                                                                                                            "value": 1.6877105,
                                                                                                                                            "description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
                                                                                                                                            "details": [
                                                                                                                                                {
                                                                                                                                                    "value": 1,
                                                                                                                                                    "description": "termFreq=1.0",
                                                                                                                                                    "details": []
                                                                                                                                                },
                                                                                                                                                {
                                                                                                                                                    "value": 1.2,
                                                                                                                                                    "description": "parameter k1",
                                                                                                                                                    "details": []
                                                                                                                                                },
                                                                                                                                                {
                                                                                                                                                    "value": 0.75,
                                                                                                                                                    "description": "parameter b",
                                                                                                                                                    "details": []
                                                                                                                                                },
                                                                                                                                                {
                                                                                                                                                    "value": 1807.3713,
                                                                                                                                                    "description": "avgFieldLength",
                                                                                                                                                    "details": []
                                                                                                                                                },
                                                                                                                                                {
                                                                                                                                                    "value": 7.111111,
                                                                                                                                                    "description": "fieldLength",
                                                                                                                                                    "details": []
                                                                                                                                                }
                                                                                                                                            ]
                                                                                                                                        }
                                                                                                                                    ]
                                                                                                                                }
                                                                                                                            ]
                                                                                                                        }
                                                                                                                    ]
                                                                                                                },
                                                                                                                {
                                                                                                                    "value": 0,
                                                                                                                    "description": "match on required clause, product of:",
                                                                                                                    "details": [
                                                                                                                        {
                                                                                                                            "value": 0,
                                                                                                                            "description": "# clause",
                                                                                                                            "details": []
                                                                                                                        },
                                                                                                                        {
                                                                                                                            "value": 1,
                                                                                                                            "description": "_type:__elements, product of:",
                                                                                                                            "details": [
                                                                                                                                {
                                                                                                                                    "value": 1,
                                                                                                                                    "description": "boost",
                                                                                                                                    "details": []
                                                                                                                                },
                                                                                                                                {
                                                                                                                                    "value": 1,
                                                                                                                                    "description": "queryNorm",
                                                                                                                                    "details": []
                                                                                                                                }
                                                                                                                            ]
                                                                                                                        }
                                                                                                                    ]
                                                                                                                }
                                                                                                            ]
                                                                                                        }
                                                                                                    ]
                                                                                                }
                                                                                            ]
                                                                                        }
                                                                                    ]
                                                                                },
                                                                                {
                                                                                    "value": 1,
                                                                                    "description": "sum of:",
                                                                                    "details": [
                                                                                        {
                                                                                            "value": 1,
                                                                                            "description": "*:*, product of:",
                                                                                            "details": [
                                                                                                {
                                                                                                    "value": 1,
                                                                                                    "description": "boost",
                                                                                                    "details": []
                                                                                                },
                                                                                                {
                                                                                                    "value": 1,
                                                                                                    "description": "queryNorm",
                                                                                                    "details": []
                                                                                                }
                                                                                            ]
                                                                                        }
                                                                                    ]
                                                                                }
                                                                            ]
                                                                        },
                                                                        {
                                                                            "value": 0,
                                                                            "description": "match on required clause, product of:",
                                                                            "details": [
                                                                                {
                                                                                    "value": 0,
                                                                                    "description": "# clause",
                                                                                    "details": []
                                                                                },
                                                                                {
                                                                                    "value": 1,
                                                                                    "description": "#*:* -_type:__*, product of:",
                                                                                    "details": [
                                                                                        {
                                                                                            "value": 1,
                                                                                            "description": "boost",
                                                                                            "details": []
                                                                                        },
                                                                                        {
                                                                                            "value": 1,
                                                                                            "description": "queryNorm",
                                                                                            "details": []
                                                                                        }
                                                                                    ]
                                                                                }
                                                                            ]
                                                                        }
                                                                    ]
                                                                },
                                                                {
                                                                    "value": 1,
                                                                    "description": "primaryWeight",
                                                                    "details": []
                                                                }
                                                            ]
                                                        },
                                                        {
                                                            "value": 16.274069,
                                                            "description": "product of:",
                                                            "details": [
                                                                {
                                                                    "value": 16.274069,
                                                                    "description": "max of:",
                                                                    "details": [
                                                                        {
                                                                            "value": 16.274069,
                                                                            "description": "weight(elements.content.search:goz in 5) [PerFieldSimilarity], result of:",
                                                                            "details": [
                                                                                {
                                                                                    "value": 16.274069,
                                                                                    "description": "score(doc=5,freq=1.0 = termFreq=1.0\n), product of:",
                                                                                    "details": [
                                                                                        {
                                                                                            "value": 3,
                                                                                            "description": "boost",
                                                                                            "details": []
                                                                                        },
                                                                                        {
                                                                                            "value": 3.2142298,
                                                                                            "description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
                                                                                            "details": [
                                                                                                {
                                                                                                    "value": 116,
                                                                                                    "description": "docFreq",
                                                                                                    "details": []
                                                                                                },
                                                                                                {
                                                                                                    "value": 2898,
                                                                                                    "description": "docCount",
                                                                                                    "details": []
                                                                                                }
                                                                                            ]
                                                                                        },
                                                                                        {
                                                                                            "value": 1.6877105,
                                                                                            "description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
                                                                                            "details": [
                                                                                                {
                                                                                                    "value": 1,
                                                                                                    "description": "termFreq=1.0",
                                                                                                    "details": []
                                                                                                },
                                                                                                {
                                                                                                    "value": 1.2,
                                                                                                    "description": "parameter k1",
                                                                                                    "details": []
                                                                                                },
                                                                                                {
                                                                                                    "value": 0.75,
                                                                                                    "description": "parameter b",
                                                                                                    "details": []
                                                                                                },
                                                                                                {
                                                                                                    "value": 1807.3713,
                                                                                                    "description": "avgFieldLength",
                                                                                                    "details": []
                                                                                                },
                                                                                                {
                                                                                                    "value": 7.111111,
                                                                                                    "description": "fieldLength",
                                                                                                    "details": []
                                                                                                }
                                                                                            ]
                                                                                        }
                                                                                    ]
                                                                                }
                                                                            ]
                                                                        }
                                                                    ]
                                                                },
                                                                {
                                                                    "value": 1,
                                                                    "description": "secondaryWeight",
                                                                    "details": []
                                                                }
                                                            ]
                                                        }
                                                    ]
                                                },
                                                {
                                                    "value": 1,
                                                    "description": "primaryWeight",
                                                    "details": []
                                                }
                                            ]
                                        },
                                        {
                                            "value": 148.19745,
                                            "description": "product of:",
                                            "details": [
                                                {
                                                    "value": 1.8524681,
                                                    "description": "max of:",
                                                    "details": [
                                                        {
                                                            "value": 1.8524681,
                                                            "description": "weight(elements.content.stem:goz in 5) [PerFieldSimilarity], result of:",
                                                            "details": [
                                                                {
                                                                    "value": 1.8524681,
                                                                    "description": "score(doc=5,freq=2.0 = termFreq=2.0\n), product of:",
                                                                    "details": [
                                                                        {
                                                                            "value": 3.2315464,
                                                                            "description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
                                                                            "details": [
                                                                                {
                                                                                    "value": 114,
                                                                                    "description": "docFreq",
                                                                                    "details": []
                                                                                },
                                                                                {
                                                                                    "value": 2898,
                                                                                    "description": "docCount",
                                                                                    "details": []
                                                                                }
                                                                            ]
                                                                        },
                                                                        {
                                                                            "value": 0.5732451,
                                                                            "description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
                                                                            "details": [
                                                                                {
                                                                                    "value": 2,
                                                                                    "description": "termFreq=2.0",
                                                                                    "details": []
                                                                                },
                                                                                {
                                                                                    "value": 1.2,
                                                                                    "description": "parameter k1",
                                                                                    "details": []
                                                                                },
                                                                                {
                                                                                    "value": 0.75,
                                                                                    "description": "parameter b",
                                                                                    "details": []
                                                                                },
                                                                                {
                                                                                    "value": 223.9234,
                                                                                    "description": "avgFieldLength",
                                                                                    "details": []
                                                                                },
                                                                                {
                                                                                    "value": 1337.4694,
                                                                                    "description": "fieldLength",
                                                                                    "details": []
                                                                                }
                                                                            ]
                                                                        }
                                                                    ]
                                                                }
                                                            ]
                                                        }
                                                    ]
                                                },
                                                {
                                                    "value": 80,
                                                    "description": "secondaryWeight",
                                                    "details": []
                                                }
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "value": 1,
                                    "description": "primaryWeight",
                                    "details": []
                                }
                            ]
                        }
krueger commented 6 years ago

This is the rescorer part of the query:

"rescore" : [
    {
      "query" : {
        "rescore_query" : {
          "multi_match" : {
            "query" : "goz",
            "fields" : [
              "elements.content.search^1.0",
              "elements.tags^1.0",
              "elements.title.search^1.0"
            ],
            "type" : "best_fields",
            "operator" : "AND",
            "slop" : 0,
            "prefix_length" : 0,
            "max_expansions" : 50,
            "lenient" : false,
            "zero_terms_query" : "NONE",
            "boost" : 1.0
          }
        },
        "query_weight" : 1.0,
        "rescore_query_weight" : 1.0,
        "score_mode" : "total"
      }
    },
    {
      "query" : {
        "rescore_query" : {
          "multi_match" : {
            "query" : "goz",
            "fields" : [
              "elements.content.stem^1.0",
              "elements.tags^1.0",
              "elements.title.stem^1.0"
            ],
            "type" : "phrase",
            "operator" : "OR",
            "slop" : 0,
            "prefix_length" : 0,
            "max_expansions" : 50,
            "lenient" : false,
            "zero_terms_query" : "NONE",
            "boost" : 1.0
          }
        },
        "query_weight" : 1.0,
        "rescore_query_weight" : 80.0,
        "score_mode" : "total"
      }
    },
    {
      "query" : {
        "rescore_query" : {
          "match" : {
            "elements.content.stem" : {
              "query" : "goz",
              "operator" : "AND",
              "prefix_length" : 0,
              "max_expansions" : 50,
              "fuzzy_transpositions" : true,
              "lenient" : false,
              "zero_terms_query" : "NONE",
              "boost" : 1.0
            }
          }
        },
        "query_weight" : 1.0,
        "rescore_query_weight" : 2.0,
        "score_mode" : "total"
      }
    }
  ]
krueger commented 6 years ago

The problem is that the field _score does not contain the rescore value if result is sorted by score. This happens when adding requestBuilder.addSort(SortBuilders.scoreSort());

elasticmachine commented 6 years ago

Pinging @elastic/es-search-aggs

colings86 commented 6 years ago

@cbuescher could you take a look at this?

cbuescher commented 6 years ago

Hi @krueger, from the first snippet it looks like you are sorting on different criterea, not just "_score". Am I right, and could you send the whole query you are basing this issue on?

krueger commented 6 years ago

This is the complete query: complete_query.txt

I also checked if there is a difference between requesting _score only and _score with other sort fields. The behavior only occurs if _score with other sort fields is requested.

cbuescher commented 6 years ago

Hi, did another code and docs search around this and it seems like using "sort" with anything other than "_score" seems to be not supported by design at the moment. The 5.x documentation has a note that "the rescore phase is not executed when sort is used." (https://www.elastic.co/guide/en/elasticsearch/reference/5.6/search-request-rescore.html and earlier 5.x versions) while this is relaxed in 6.x and master to say "An error will be thrown if an explicit sort (other than _score) is provided with a rescore query." (https://www.elastic.co/guide/en/elasticsearch/reference/6.x/search-request-rescore.html), which is actually what I get when I try to run a simplified version of your query on 6.3. I found this issue that introduced throwing that error instead of silently ignoring the rescore phase which dicusses several arguments around why this isn't supported: https://github.com/elastic/elasticsearch/pull/26510

Hope this clears things up and you don't mind me closing this.