How to search \t \r \n in elasticsearch?

I want to search \t \r \n in my doc, how to input in query string syntax.

It seems "\n" can work , "\n","\n" not work ,
Is there any other choises?

POST /test6/_doc/2
{
    "id": 1002,
    "name": "test1",
    "desc": "Marvin \n \t \r "
}
POST test6/_close  
POST test6/_open  
PUT /test6/_settings
{
            "analysis": {
                "analyzer": {
                    "default": {
                        "tokenizer": "default",
                        "filter": null
                    }
                },
                "tokenizer": {
                    "default": {
                        "type": "char_group",
                        "tokenize_on_chars": [
                            " "
                        ]
                    }
                }
            }
}

POST  test6/_search
{"query":{"query_string":{"query":"\\t"}}
}
POST  test6/_search
{"query":{"query_string":{"query":"\"\t\""}}
}
POST  test6/_search
{"query":{"query_string":{"query":"\t"}}
}
POST  test6/_search
{"query":{"query_string":{"query":"Marvin"}}
}

You need to configure the analyzer for a field before indexing your data (at best at index creation), as otherwise those characters are not stored in the inverted index. You only have configured your analyzer to be in the index configuration, but it is not applide to any field. Side note: You could go with the whitespace tokenizer as well.

Out of curiosity: What problem are you solving in order to be able to search for control characters? Can you add some more context about the use-case?

1 Like