Hello,
I'm running into issues with inconsistently scored documents between
different index configurations, and I think may be misunderstanding
some of the basics of how scores are calculated. Repro details are
below, but my basic question is how a hit's _score relates to its
_explanation.value (provided when "explain" : true is set in the
query). I understand scores are by default calculated within each
shard, but I thought passing search_type=dfs_query_then_fetch would
lead to the calculation of globally "correct" scores.
Repro steps:
[start with empty index, configured with 1 or 2 shards as called out
below]
curl -XPUT http://localhost:9200/index/mytype/1 -d '{ "name" : "Foo
Bar" }'
curl -XPUT http://localhost:9200/index/mytype/2 -d '{ "name" : "Foo
Zip" }'
curl -XPUT http://localhost:9200/index/mytype/3 -d '{ "name" : "Zap
Foo" }'
curl -XPUT http://localhost:9200/index/mytype/4 -d '{ "name" :
"Something Else" }'
When the index is configure to use one shard, I get the following
results as expected. Note this is the desired result ("Foo Bar" is
scored highest and "Foo Zip" and "Zap Foo" are tied for second best).
curl -XGET 'localhost:9200/index/mytype/_search?pretty=1' -d '{"query":
{"bool":{"must":[{"text":{"name":"Foo Bar"}}]}}, "explain":true}'
{
"took" : 40,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.2290028,
"hits" : [ {
"_shard" : 0,
...
"_id" : "1",
"_score" : 1.2290028, "_source" : { "name" : "Foo Bar" },
"_explanation" : {
"value" : 1.229003,
...
}, {
"_shard" : 0,
...
"_id" : "2",
"_score" : 0.15891947, "_source" : { "name" : "Foo Zip" },
"_explanation" : {
"value" : 0.15891947,
...
}, {
"_shard" : 0,
...
"_id" : "3",
"_score" : 0.15891947, "_source" : { "name" : "Zap Foo" },
"_explanation" : {
"value" : 0.15891947,
...
} ]
}
}
When the index is configured to use two shards, I get the following
results as expected. Note these results aren't desirable since "Zap
Foo" is being scored lower than "Foo Zip", but they're expected since
the documents are stored in different shards and
search_type=dfs_query_then_fetch isn't specified.
curl -XGET 'localhost:9200/index/mytype/_search?pretty=1' -d '{"query":
{"bool":{"must":[{"text":{"name":"Foo Bar"}}]}}, "explain":true}'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 0.72711754,
"hits" : [ {
"_shard" : 0,
...
"_id" : "1",
"_score" : 0.72711754, "_source" : { "name" : "Foo Bar" },
"_explanation" : {
"value" : 0.7271175,
...
}, {
"_shard" : 1,
...
"_id" : "2",
"_score" : 0.15891947, "_source" : { "name" : "Foo Zip" },
"_explanation" : {
"value" : 0.15891947,
...
}, {
"_shard" : 0,
...
"_id" : "3",
"_score" : 0.09494676, "_source" : { "name" : "Zap Foo" },
"_explanation" : {
"value" : 0.09494675,
...
} ]
}
}
In the two previous cases, _explanation.value matches _score for each
hit, which is what I'd expect from the _explanation data structure.
Now, with the 2-shard index again, I'd expect specifying
search_type=dfs_query_then_fetch would provide me with the desired
results of "Foo Bar" matching highest and "Foo Zip" and "Zap Foo"
tying for second best.
curl -XGET 'localhost:9200/index/mytype/_search?
pretty=1&search_type=dfs_query_then_fetch' -d '{"query":{"bool":
{"must":[{"text":{"name":"Foo Bar"}}]}}, "explain":true}'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 0.72711754,
"hits" : [ {
"_shard" : 0,
...
"_id" : "1",
"_score" : 0.72711754, "_source" : { "name" : "Foo Bar" },
"_explanation" : {
"value" : 1.229003,
...
}, {
"_shard" : 1,
...
"_id" : "2",
"_score" : 0.15891947, "_source" : { "name" : "Foo Zip" },
"_explanation" : {
"value" : 0.15891947,
...
}, {
"_shard" : 0,
...
"_id" : "3",
"_score" : 0.09494676, "_source" : { "name" : "Zap Foo" },
"_explanation" : {
"value" : 0.15891947,
...
} ]
}
}
Note in this case _explanation.value does not match _score for hits 1
and 3, and _score for hits 2 and 3 differ even though
_explanation.value matches. What is causing _explanation.value to
change for the final _score field? If someone could point out to me
what I'm missing about the relationship between _score and
_explanation.value, I'd very much appreciate it.
Ideally, the results from my search system would be consistent between
indexing runs using generated document IDs (or, stated differently,
the shard allocation would not affect document scoring). Is that
achievable?
Thanks,
Cole