# Painless - Getting Field with whitespace Character

**URL:** <https://discuss.elastic.co/t/painless-getting-field-with-whitespace-character/109223>\
**Category:** Elasticsearch\
**Created:** [November 27, 2017, 1:14pm UTC](https://discuss.elastic.co/t/painless-getting-field-with-whitespace-character/109223 "2017-11-27T13:14:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcam/32/51518_2.png) [@dcam](https://discuss.elastic.co/u/dcam)\
**Post date:** [November 27, 2017, 1:14pm UTC](https://discuss.elastic.co/t/painless-getting-field-with-whitespace-character/109223/1 "2017-11-27T13:14:14Z")

</div>

I have a field with Whitespace character: i.e 'Error Message.keyword'

How can I get this field with painless?

1 ) `ctx.payload.buckets[0].'Error Message.keyword'`  
2 ) `def error='Error Message.keyword'; ctx.payload.buckets[0].error`

Both above versions do not work.

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [November 27, 2017, 4:50pm UTC](https://discuss.elastic.co/t/painless-getting-field-with-whitespace-character/109223/2 "2017-11-27T16:50:56Z")

</div>

You need to use brackets to access a key from a map.

```auto
ctx.payload.buckets[0]['Error Message.keyword']

```

---

<div class="post-metadata">

**Author:** ![dcam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcam/32/51518_2.png) [@dcam](https://discuss.elastic.co/u/dcam)\
**Post date:** [November 27, 2017, 5:01pm UTC](https://discuss.elastic.co/t/painless-getting-field-with-whitespace-character/109223/3 "2017-11-27T17:01:01Z")

</div>

Worked!

Why do I get "**[]**? How can I get rid of []?

```
      "payload": {
        "error": "[no user found]"
      }
```

---

<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:** [December 25, 2017, 5:01pm UTC](https://discuss.elastic.co/t/painless-getting-field-with-whitespace-character/109223/4 "2017-12-25T17:01:10Z")

</div>

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