2

I defined a custom analyzer that I was surprised not built-in.

analyzer": {
    "keyword_lowercase": {
        "type": "custom",
        "filter": [
            "lowercase"
        ],
        "tokenizer": "keyword"
    }
}

Then my mapping for this field is:

"email": {
    "type": "string",
    "analyzer": "keyword_lowercase"
}

This works great. (http://.../_analyze?field=email&[email protected]) ->

"tokens": [
    {
        "token": "[email protected]",
        "start_offset": 0,
        "end_offset": 16,
        "type": "word",
        "position": 1
    }
]

Finding by that keyword works great. http://.../[email protected] yields results.

The problem is trying to incorporate wildcards anywhere in the Query String Query. http://.../_search?q=*[email protected] yields no results. I would expect results containing emails such as "[email protected]" and "[email protected]".

It looks like elasticsearch performs the search with the default analyzer, which doesn't make sense. Shouldn't it perform the search with each field's own default analyzer?

I.E. http://.../_search?q=email:*[email protected] returns results because I am telling it which analyzer to use based upon the field.

Can elasticsearch not do this?

4
  • Can you post your query that uses query_string? It may be that you're not telling elasticsearch which field to search - if so it will use the _all field, which is an automatically generated combination of all the fields and uses the standard analyser. Commented Jan 21, 2015 at 19:31
  • the _search?q= is a query string query. See elasticsearch.org/guide/en/elasticsearch/reference/current/… Yes, it uses _all. So, from what you said, it is as I figured. It uses the standard analyzer for all fields, not the each field's default analyzer. Commented Jan 21, 2015 at 20:53
  • to add on wildcard queries are not analyzed as a result they do not match in the _all field. Commented Jan 21, 2015 at 20:56
  • Ooh, I need to use the full query search query (elasticsearch.org/guide/en/elasticsearch/reference/current/…) and set analyze_wildcard to true. This fixes my issue. Commented Jan 21, 2015 at 21:33

1 Answer 1

1

See http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html

Set analyze_wildcard to true, as it is false by default.

Sign up to request clarification or add additional context in comments.

1 Comment

Does this solution work for a query containing the "+" symbol. For exemple , I search "HTC One M9+". Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.