# Doc\['message.keyword'\] shows 0 value for given index but actually value is present in message field. What could be the reason?

**URL:** <https://discuss.elastic.co/t/doc-message-keyword-shows-0-value-for-given-index-but-actually-value-is-present-in-message-field-what-could-be-the-reason/301299>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [April 1, 2022, 9:30am UTC](https://discuss.elastic.co/t/doc-message-keyword-shows-0-value-for-given-index-but-actually-value-is-present-in-message-field-what-could-be-the-reason/301299 "2022-04-01T09:30:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vishdubey](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vishdubey](https://discuss.elastic.co/u/vishdubey)\
**Post date:** [April 1, 2022, 9:30am UTC](https://discuss.elastic.co/t/doc-message-keyword-shows-0-value-for-given-index-but-actually-value-is-present-in-message-field-what-could-be-the-reason/301299/1 "2022-04-01T09:30:00Z")

</div>

below is the script field

```auto
GET log-2022.03.30/_search
{
  "script_fields": {
    "message": {
      "script": {
        "lang" : "painless",
        "source": "doc['message.keyword'].value"
      }
    }
  }
}

```

and here is the result I got

```auto
"failures" : [
      {
        "shard" : 0,
        "index" : "log-2022.03.30",
        "node" : "Jei35aKrR0-jxyKKld12jss",
        "reason" : {
          "type" : "script_exception",
          "reason" : "runtime error",
          "script_stack" : [
            "org.elasticsearch.index.fielddata.ScriptDocValues$Strings.get(ScriptDocValues.java:494)",
            "org.elasticsearch.index.fielddata.ScriptDocValues$Strings.getValue(ScriptDocValues.java:508)",
            "doc['message.keyword'].value",
            " ^---- HERE"
          ],
          "script" : "doc['message.keyword'].value",
          "lang" : "painless",
          "position" : {
            "offset" : 22,
            "start" : 0,
            "end" : 28
          },
          "caused_by" : {
            "type" : "illegal_state_exception",
            "reason" : "A document doesn't have a value for a field! Use doc[<field>].size()==0 to check if a document is missing a field!"
          }
        }
      }
    ]

```

Kindly help on this.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 4, 2022, 11:14am UTC](https://discuss.elastic.co/t/doc-message-keyword-shows-0-value-for-given-index-but-actually-value-is-present-in-message-field-what-could-be-the-reason/301299/2 "2022-04-04T11:14:40Z")

</div>

Hey,

why is it not possible, that any of your documents does **not** have the message field set? Can you verify that using an exists query for that field, no documents are returned? Can you provide a fully reproducible example, that contains a sample document containing a message field and that error message, so we can reproduce locally?

--Alex

---

<div class="post-metadata">

**Author:** ![vishdubey](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vishdubey](https://discuss.elastic.co/u/vishdubey)\
**Post date:** [April 6, 2022, 8:14am UTC](https://discuss.elastic.co/t/doc-message-keyword-shows-0-value-for-given-index-but-actually-value-is-present-in-message-field-what-could-be-the-reason/301299/3 "2022-04-06T08:14:12Z")

</div>

Hi Spinscale ,  
every document have the message field with some data present to it.  
I have verified it with query and got the data. but the only issue is when I try to read data with 'message.keyword' it gives no data. Below is the query :-

```auto
GET logstash-index-xxx/_search
{
  "size": 0, 
  "aggs": {
    "message": {
      "terms": {
        "script": {
          "source": "doc['message.keyword'].value"
        }
      }
    }
  }
}

```

As of now I have resolved the issue with enabling **'fielddata=true'** but now the issue is when I try to see the logs for 7 days or more, It takes longer time and eventually fails giving internal server error ("failed to execute")

---

<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:** [May 4, 2022, 8:14am UTC](https://discuss.elastic.co/t/doc-message-keyword-shows-0-value-for-given-index-but-actually-value-is-present-in-message-field-what-could-be-the-reason/301299/4 "2022-05-04T08:14:23Z")

</div>

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