Unexpected search response for nested objects

Step 1: Create mapping nested document:
curl -XPUT --header 'Content-Type: application/json' http://es:9200/search -d '{"mappings" : { "hometable" : { "properties":{ "recipes":{ "type":"nested", "properties":{ "id":{ "type":"text" }, "description":{ "type":"text" } } } } } } }'

Step 2: Insert nested doc. 1:
curl -H "Content-Type: application/json" -XPUT "http://es:9200/search/hometable/1" -d '{"recipes":[{ "description":"the green curry is fresh and hot","id":"1" }, { "description":"the pasta saus is creamy", "id":"2" }] }'

Step 3: Insert nested doc. 2:
curl -H "Content-Type: application/json" -XPUT "http://es:9200/search/hometable/2" -d '{"recipes": [{ "description":"red curry full of wonderful spices", "id":"1" }] }',

Step 4: Search request:
curl -XGET --header 'Content-Type: application/json' http://es:9200/search/_search/?pretty=true -d '{"query":{ "bool":{ "must":[{ "nested":{ "query":{ "bool":{ "should":[{ "match":{ "recipes.description":{ "query": "red curry" } } }] } }, "path":"recipes", "inner_hits":{} } }] } } }'

Result 1: Search response: red curry has the lower score

   ...
      "hits" : {
        "total" : 2,
        "max_score" : 0.6489038,
        "hits" : [
          {
            ...
            "_id" : "1",
            "_score" : 0.6489038,
            "_source" : {
              "recipes" : [
                {
                  "description" : "the green curry is fresh and hot",
                  "id" : "1"
                },
                {
                  "description" : "the pasta saus is creamy",
                  "id" : "2"
                }
              ]
            },
            "inner_hits" : {
              "recipes" : {
                "hits" : {
                  "total" : 1,
                  "max_score" : 0.6489038,
                  "hits" : [
                    {
                      ...
                      "_id" : "1",
                      "_nested" : {
                        "field" : "recipes"
                      },
                      "_score" : 0.6489038,
                      "_source" : {
                        "description" : "the green curry is fresh and hot",
                        "id" : "1"
                      }
                    }
                  ]
                }
              }
            }
          },
          {
            ...
            "_id" : "2",
            "_score" : 0.5753642,
            "_source" : {
              "recipes" : [
                {
                  "description" : "red curry full of wonderful spices",
                  "id" : "1"
                }
              ]
            },
            "inner_hits" : {
              "recipes" : {
                "hits" : {
                  "total" : 1,
                  "max_score" : 0.5753642,
                  "hits" : [
                    {
                      "_index" : "search",
                      "_type" : "hometable",
                      "_id" : "2",
                      "_nested" : {
                        "field" : "recipes"
                      },
                      "_score" : 0.5753642,
                      "_source" : {
                        "description" : "red curry full of wonderful spices",
                        "id" : "1"
                      }
                    }
                  ]
...
    }

The following test shows this is probably due to the 2nd nested doc. that some how influences the overall score.

Step 5: Update nested document 1 (remove 2 nested document):
curl -H "Content-Type: application/json" -XPUT "http://es:9200/search/hometable/1" -d '{"recipes":[{ "description":"the green curry is fresh and hot","id":"1" }] }'

Result 2: Search response for the previous search request: the expected result is returned with the higher score for "red curry".

{
 ...

      "hits" : {
        "total" : 2,
        "max_score" : 0.5753642,
        "hits" : [
          {
           ..
            "_id" : "2",
            "_score" : 0.5753642,
            "_source" : {
              "recipes" : [
                {
                  "description" : "red curry full of wonderful spices",
                  "id" : "1"
                }
              ]
            },
            "inner_hits" : {
              "recipes" : {
                "hits" : {
                  "total" : 1,
                  "max_score" : 0.5753642,
                  "hits" : [
                    {
                      ...
                      "_id" : "2",
                      "_nested" : {
                        "field" : "recipes",
                        "offset" : 0
                      },
                      "_score" : 0.5753642,
                      "_source" : {
                        "description" : "red curry full of wonderful spices",
                        "id" : "1"
                      }
                    }
                  ]
                }
              }
            }
          },
          {
            ...
            "_id" : "1",
            "_score" : 0.2876821,
            "_source" : {
              "recipes" : [
                {
                  "description" : "the green curry is fresh and hot",
                  "id" : "1"
                }
              ]
            },
            "inner_hits" : {
              "recipes" : {
                "hits" : {
                  "total" : 1,
                  "max_score" : 0.2876821,
                  "hits" : [
                    {
                      ...
                      "_nested" : {
                        "field" : "recipes"
                      },
                      "_score" : 0.2876821,
                      "_source" : {
                        "description" : "the green curry is fresh and hot",
                        "id" : "1"
                      }
                    }
                  ]
                }
...
    }

Question
Why does "red curry" have the lower score when its the better match as can be seen in result 1"
What can/must I do in order to achieve the excepted result?

Any help would greatly be appreciated!

Regards Benny

It looks like the document with 2 nested objects some how influences the score even though it does not match the search query.
Why?

Regards Benny

Problem solved!
After updating to elasticsearch v7.3.0 expected results are retrieved.

Regards Benny

FYI: Unexpected result were in versions 6.x.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.