Search string with special characters

Hi,
I am using ES 5.1.2.

I would like to store emails (or any other string with special characters for that matter), and enable ngram search.

For example: Store "carlos.santana.1925@yat.co.tod".

Return the document when searching for "19 25@ya ".

BUT, not return it when searching "carlos.santana.19-25@yat.co.tod".

I defined the field like so:
"address": {
"type": "text",
"fields": {
"email_field": {
"type": "text",
"analyzer": "ngram_with_special_chars",
"search_analyzer": "keyword"
}
},
"analyzer": "ngram_with_special_chars",
"search_analyzer": "keyword"
}

Where:

Filter:
"lang_ngram_special_char_filter": {
"token_chars": "[]",
"min_gram": "2",
"type": "nGram",
"max_gram": "10"
}

Analyzers:
"ngram_with_special_chars": {
"filter": [
"lowercase",
"spanish_stop",
"spanish_keywords",
"lang_ngram_special_char_filter"
],
"type": "custom",
"tokenizer": "keyword"
},

"keyword": {
"filter": [
"all_chars_included_in_token"
],
"type": "custom",
"tokenizer": "uax_url_email"
},

BUT:

GET /person_index/_search
{
      "query": {
                "bool": {
                       "should" : {
                              "query_string" : { 
                                "query": "carlos.santana.19-25@yat.co.tod"
                              }
                       }
                }    
          },
          "explain": true,
          "highlight": {
            "fields": {
              "*": {}
            }
      }
}

Still finds the string "carlos.santana.1925@yat.co.tod".

How to make it not find it?

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.

I feel like you should specify on which field you are searching. Like with a match query on address . email_field.

If you don't succeed I'd recommend that you provide a full recreation script as described in About the Elasticsearch category. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

The </> icon didn't help much.

But anyways, I copied and pasted from kibana.

As for search, I am not searching on a specific field. I'm searching just like in the query I put: all indexes and fields.

It works for me:

foo();
bar();

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