# How to escape field values for elasticsearch filter query?

**URL:** <https://discuss.elastic.co/t/how-to-escape-field-values-for-elasticsearch-filter-query/125386>\
**Category:** Logstash\
**Created:** [March 23, 2018, 3:37pm UTC](https://discuss.elastic.co/t/how-to-escape-field-values-for-elasticsearch-filter-query/125386 "2018-03-23T15:37:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdmcalee](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jdmcalee](https://discuss.elastic.co/u/jdmcalee)\
**Post date:** [March 23, 2018, 3:37pm UTC](https://discuss.elastic.co/t/how-to-escape-field-values-for-elasticsearch-filter-query/125386/1 "2018-03-23T15:37:59Z")

</div>

I'm using the elasticsearch filter to enrich an event coming from a database. I'm using a fairly simple query:

```
query => "usernames.keyword:%{[userid]}@%{[domain]}"

```

It works fine, usually. However, I have instances where the userid field contains a forward slash. In that case, Elasticsearch fails to parse the query, because the slash isn't being escaped. Is there a better way to accomplish that (for all characters that need escaping) than using a mutate filter before the elasticsearch filter to populate a temporary field to be used in the elasticsearch query?

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [March 26, 2018, 1:22pm UTC](https://discuss.elastic.co/t/how-to-escape-field-values-for-elasticsearch-filter-query/125386/2 "2018-03-26T13:22:09Z")

</div>

```
query => 'usernames.keyword:"%{[userid]}@%{[domain]}"'

```

Recent versions of Logstash supports standard escapes in strings if you enable it with a command-line option.

---

<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:** [April 23, 2018, 1:22pm UTC](https://discuss.elastic.co/t/how-to-escape-field-values-for-elasticsearch-filter-query/125386/3 "2018-04-23T13:22:12Z")

</div>

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