# A document doesn't have a value for a field error, but the field has values

**URL:** <https://discuss.elastic.co/t/a-document-doesnt-have-a-value-for-a-field-error-but-the-field-has-values/276839>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [June 23, 2021, 7:10pm UTC](https://discuss.elastic.co/t/a-document-doesnt-have-a-value-for-a-field-error-but-the-field-has-values/276839 "2021-06-23T19:10:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [June 23, 2021, 7:10pm UTC](https://discuss.elastic.co/t/a-document-doesnt-have-a-value-for-a-field-error-but-the-field-has-values/276839/1 "2021-06-23T19:10:29Z")

</div>

Hi, i got a field with values like this

```auto
InstanceName CPU   
------------ ---   
mfemvedr 1,17 %
macmnsvc 0,78 %
services 0,39 %
svchost 0,00 %
searchindexer 0,00 %
googlecrashhandler 0,00 %
googlecrashhandler64 0,00 %
wmiprvse 0,00 %
csrss 0,00 %
winlogon 0,00 %

```

and when I try to get the value with script\_fields, gives me the following error:  
`A document doesn't have a value for a field`

this is part of the query, I have another script\_fields in the query and they work

```auto
  "script_fields": {
    "top": {
      "script": {
        "lang": "painless",
        "source": """doc["tops.keyword"].value"""
      }
    }
  }

```

this is how the values looks like in Kibana Discover:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/1/91ea637635ba8ceae1825e2ae1bbde0716e96a4d.png)

Why Im getting this error? could be that the values contains special characters? line breaks?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 24, 2021, 5:35am UTC](https://discuss.elastic.co/t/a-document-doesnt-have-a-value-for-a-field-error-but-the-field-has-values/276839/2 "2021-06-24T05:35:28Z")

</div>

Can you show us the json representation of that `tops` field?

---

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [June 24, 2021, 5:46am UTC](https://discuss.elastic.co/t/a-document-doesnt-have-a-value-for-a-field-error-but-the-field-has-values/276839/3 "2021-06-24T05:46:44Z")

</div>

Hi Warkolm, I have manipulated a little bit the values with logstash (remove spaces), but still get the same error, so maybe is not the line breaks...

```auto
  "hits" : [
      {
        "_index" : "zabbix-top-ml-2021.06.24.05",
        "_type" : "_doc",
        "_id" : "_xBkPHoBGx_ftYrRjRMj",
        "_score" : 0.69084567,
        "_source" : {
          "hostname" : "SRVAAMAGICTVP",
          "@timestamp" : "2021-06-24T05:00:57.000Z",
          "tops" : "InstanceNameCPU---------------keytool-24,85%wmiprvse-5,05%mamain-3,11%mfemvedr-2,72%nscp-0,78%wmiprvse-0,39%macmnsvc-0,39%csrss-0,39%ir_agent-0,00%jucheck-0,00%"
        }
      },

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [June 24, 2021, 5:48am UTC](https://discuss.elastic.co/t/a-document-doesnt-have-a-value-for-a-field-error-but-the-field-has-values/276839/4 "2021-06-24T05:48:23Z")

</div>

Ok, you probably need to break that field out before indexing it, because the value of `tops.keyword` is going to be `InstanceNameCPU---------------keytool-24,85%wmiprvse-5,05%mamain-3,11%mfemvedr-2,72%nscp-0,78%wmiprvse-0,39%macmnsvc-0,39%csrss-0,39%ir_agent-0,00%jucheck-0,00%`

---

<div class="post-metadata">

**Author:** ![ElasticLiver](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/elasticliver/32/64869_2.png) [@ElasticLiver](https://discuss.elastic.co/u/ElasticLiver)\
**Post date:** [June 24, 2021, 3:34pm UTC](https://discuss.elastic.co/t/a-document-doesnt-have-a-value-for-a-field-error-but-the-field-has-values/276839/5 "2021-06-24T15:34:27Z")

</div>

Why do you think that can not be a single string?

---

<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:** [July 22, 2021, 3:35pm UTC](https://discuss.elastic.co/t/a-document-doesnt-have-a-value-for-a-field-error-but-the-field-has-values/276839/6 "2021-07-22T15:35:10Z")

</div>

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