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

**URL:** <https://discuss.elastic.co/t/missing-field-value-for-nested-field-function-score-query-v7-10-2/291365>\
**Category:** Elasticsearch\
**Created:** [December 9, 2021, 9:28pm UTC](https://discuss.elastic.co/t/missing-field-value-for-nested-field-function-score-query-v7-10-2/291365 "2021-12-09T21:28:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gursahibsahni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gursahibsahni/32/98783_2.png) [@gursahibsahni](https://discuss.elastic.co/u/gursahibsahni)\
**Post date:** [December 9, 2021, 9:28pm UTC](https://discuss.elastic.co/t/missing-field-value-for-nested-field-function-score-query-v7-10-2/291365/1 "2021-12-09T21:28:47Z")

</div>

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:

```auto
{
  "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

```auto
   "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.

```auto
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())"
                    }
                  }
                }
              ]
            }
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![gursahibsahni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gursahibsahni/32/98783_2.png) [@gursahibsahni](https://discuss.elastic.co/u/gursahibsahni)\
**Post date:** [December 9, 2021, 9:32pm UTC](https://discuss.elastic.co/t/missing-field-value-for-nested-field-function-score-query-v7-10-2/291365/2 "2021-12-09T21:32:07Z")

</div>

> [@gursahibsahni](#):
>
> `service.serviceTypeEarliestAvailability.serviceType`

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

---

<div class="post-metadata">

**Author:** ![gursahibsahni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gursahibsahni/32/98783_2.png) [@gursahibsahni](https://discuss.elastic.co/u/gursahibsahni)\
**Post date:** [December 9, 2021, 9:33pm UTC](https://discuss.elastic.co/t/missing-field-value-for-nested-field-function-score-query-v7-10-2/291365/3 "2021-12-09T21:33:35Z")

</div>

> [@gursahibsahni](#):
>
> `doc['service.serviceTypeEarliestAvailability.earliestAvailableDateTimeByType'].value.getMillis()`

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

---

<div class="post-metadata">

**Author:** ![gursahibsahni](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gursahibsahni/32/98783_2.png) [@gursahibsahni](https://discuss.elastic.co/u/gursahibsahni)\
**Post date:** [December 14, 2021, 4:51pm UTC](https://discuss.elastic.co/t/missing-field-value-for-nested-field-function-score-query-v7-10-2/291365/4 "2021-12-14T16:51:22Z")

</div>

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](https://i.stack.imgur.com/U3YfE.png)](https://i.stack.imgur.com/U3YfE.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 11, 2022, 4:52pm UTC](https://discuss.elastic.co/t/missing-field-value-for-nested-field-function-score-query-v7-10-2/291365/5 "2022-01-11T16:52:02Z")

</div>

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