Match a keyword field containing a newline character

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

"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.

 "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.

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 :slight_smile:

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.

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