Hello,
I am running a compound search query with a function score on embedded documents in my collection. However, the score returned does not seem to accurately match the value in the mapped field
data structure:
[
{
"_id": 1,
"items": [
{
"remarks": "test",
"ordering": 900000201000
}
]
}
]
query:
[
{
$search: {
index: "default",
"embeddedDocument": {
"path": "items",
"operator": {
"compound": {
"must": [
{
"text": {
"path": "items.remarks",
"query": "test"
}
}
],
"score": {
"function": {
"path": {
"value": "items.ordering"
}
}
}
}
}
},
"scoreDetails": true
}
},
{
"$project": {
"key": 1,
"items": 1,
"score": { "$meta": "searchScore" },
"scoreDetails": { "$meta": "searchScoreDetails"}
}
}
]
Index mappings:
{
"mappings": {
"dynamic": false,
"fields": {
"items": {
"dynamic": true,
"fields": {
"remarks": {
"type": "string"
},
"ordering": {
"type": "number"
}
},
"type": "embeddedDocuments"
}
}
}
}
output:
[
{
"_id": 1,
"items": [
{
"remarks": "test",
"ordering": 900000201000
}
],
"score": 900000186368,
"scoreDetails": {
"value": 900000186368,
"description": "Score based on child docs, best match:",
"details": [
{
"value": 900000186368,
"description": "FunctionScoreQuery($embedded:5/items/$type:string/items.remarks:test, scored by items.ordering) [BM25Similarity], result of:",
"details": [
{
"value": 900000186368,
"description": "items.ordering",
"details": []
}
]
}
]
}
}
]
Could you please help explain why the function score is not accurately reflecting the mapped field value? Any suggestions on how to properly score based on the embedded field?
Thank you in advance for any guidance or troubleshooting suggestions