# Match a keyword field containing a newline character

**URL:** https://discuss.elastic.co/t/match-a-keyword-field-containing-a-newline-character/219867
**Category:** Elasticsearch
**Created:** [February 18, 2020, 9:32pm UTC](https://discuss.elastic.co/t/match-a-keyword-field-containing-a-newline-character/219867 "2020-02-18T21:32:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kamiunsu](https://avatars.discourse-cdn.com/v4/letter/k/d78d45/32.png) [@kamiunsu](https://discuss.elastic.co/u/kamiunsu)
#### Post date: [February 18, 2020, 9:32pm UTC](https://discuss.elastic.co/t/match-a-keyword-field-containing-a-newline-character/219867/1 "2020-02-18T21:32:12Z")

</div>

I'm able to sort on a nested field using the following params:

```auto
"sort": [
    {
      "scores.value": {
        "mode": "sum",
        "order": "desc",
        "nested": {
          "path": "scores",
          "filter": {
            "term": {
              "scores.name": "size"
            }
          }
        }
      }
    }
  ]

```

But when a newline character is present in the string, matching fails. How can I escape or otherwise use this character to search in a keyword field? I have verified that the value is present in the documents.

```auto
 "sort": [
    {
      "scores.value": {
        "mode": "sum",
        "order": "desc",
        "nested": {
          "path": "scores",
          "filter": {
            "term": {
              "scores.name": "any string with \n character"
            }
          }
        }
      }
    }
  ]

```

Edit: Have also tried to match with regex, but can't seem to get a match to happen. Example: `(beginning of string)(.|\n)*(end of string)`. If it matters, I have other characters (e.g. `[`, `(`) that have to be escaped in these strings as well.

---

<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: [February 20, 2020, 8:31am UTC](https://discuss.elastic.co/t/match-a-keyword-field-containing-a-newline-character/219867/2 "2020-02-20T08:31:01Z")

</div>

How is this field analyzed that you are trying to execute this one? Also can you maybe provide some more context what you are trying to achieve? I am not sure that this is the most efficient solution - but I am happy to be proven wrong based on your use-case 🙂

Also a **minimal but reproducible** example, that includes index creation, mapping two sampel documents might be extremely helpful here in order for others to understand this use-case better.

---

<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: [March 19, 2020, 8:31am UTC](https://discuss.elastic.co/t/match-a-keyword-field-containing-a-newline-character/219867/3 "2020-03-19T08:31:08Z")

</div>

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