Missing Field Value For Nested Field - Function Score Query | v7.10.2

I have been trying for a long time now but the nested field value is always saying missing field value while calculating the score.

Mapping:

{
  "main_idx" : {
    "mappings" : {
      "properties" : {
        "_class" : {
          "type" : "keyword",
          "index" : false,
          "doc_values" : false
        },
        "service" : {
          "type" : "nested",
          "properties" : {
            "_class" : {
              "type" : "keyword",
              "index" : false,
              "doc_values" : false
            },
            "serviceTypeEarliestAvailability" : {
              "type" : "nested",
              "properties" : {
                "_class" : {
                  "type" : "keyword",
                  "index" : false,
                  "doc_values" : false
                },
                "earliestAvailableDateTimeByType" : {
                  "type" : "date",
                  "format" : "date_hour_minute_second"
                },
                "serviceType" : {
                  "type" : "text"
                },
                "servicesMedium" : {
                  "type" : "keyword"
                }
              }
            }
          }
        }
      }
    }
  }
}

For simplicity, I have kept just one record. Glimpse of the record

   "serviceTypeEarliestAvailability" : [
              {
                "serviceType" : "Service Type",
                "earliestAvailableDateTimeByType" : "2021-12-09T19:39:16",
                "servicesMedium" : [
                  "MED1",
                  "MED2",
                  "MED3",
                  "MED4"
                ]
              }
            ],

The following query gives: "A document doesn't have a value for a field! Use doc[].size()==0 to check if a document is missing a field!"

I tried using field_value_factor instead of script_score but it's the same problem and it complains about the missing field value.

GET /main_idx/_search
{
  "explain": true,
  "query": {
    "nested": {
      "path": "service",
      "query": {
        "nested": {
          "score_mode": "max",
          "path": "service.serviceTypeEarliestAvailability",
          "query": {
            "function_score": {
              "query": {
                "match_all": {
                  "boost": 1
                }
              },
              "functions": [
                {
                  "filter": {
                    "match": {
                      "service.serviceTypeEarliestAvailability.serviceType": "type" 
                    }
                  },
                  "weight": 10
                },
                {
                  "script_score": {
                    "script": {
          "source":     "(doc['service.serviceTypeEarliestAvailability.earliestAvailableDateTimeByType'].value.getMillis())"
                    }
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}

Somehow, this works well. Not sure about the problem with the other field.

The script would be more complicated but at first it should at least throw some value

Well, wasted a lot of time here and figured that there was no problem with the queries. Elasticsearch v7.10.2 has an issue when I try to get the explanation of the query.

It works perfectly fine without the explain parameter.

See the at org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction$1.explainScore(FieldValueFactorFunction.java:103) ~[elasticsearch-7.10.2.jar:7.10.2]

enter image description here

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