2
votes

In my ES mapping I have an 'uri' field which is currently set to not_analysed and I'm not allowed to change the mapping.I wanted to search for uri parts with a query_string query like this (this ES query is autogenerated, that is why it is a bit complicated but let's just focus on the query_string part)

{
  "sort": [{"updated": {"order": "desc"}}], 
   "query": {
     "bool": {
       "must":[{
         "query_string": {
           "query":"*w3\\.org\\/2014\\/01\\/a*", 
           "lowercase_expanded_terms": true, 
           "default_field": "uri"
         }
       }], 
       "minimum_number_should_match": 1
     }
   }, "size": 50}

Now it is usually working, but I've the following url stored (fictional url): http://w3.org/2014/01/Abc.html and this query does not bring it back because of the A-a difference. Setting the expanded terms to false also not solves this. What should I do for this query to be case insensitive?

Thanks for the help in advance.

2
I would say you need to change the mapping to achive this goal. You need a mapping to be lowercase, so if you are not allowed to do this, i have no idea how to make this work. When you set "lowercase_expanded_terms" to false than you have to search for not '../a*' but '../A*'. - Gizzmo

2 Answers

0
votes

From the docs, it seems like you need a new analyzer that first transforms to lowercase and then can run the search. Have you tried that? http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/sorting-collations.html

As I read it, your pattern, lowercase_expanded_terms, only applies to expansions, not to regular words http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html lowercase_expanded_terms Whether terms of wildcard, prefix, fuzzy, and range queries are to be automatically lower-cased or not (since they are not analyzed). Default it true

-1
votes

Try to use match query instead of query string.

{
"sort": [
    {
        "updated": {
            "order": "desc"
        }
    }
],
"query": {
    "bool": {
        "must": [
            {
                "match": {
                    "uri": "*w3\\.org\\/2014\\/01\\/a*"
                }
            }
        ]
    }
},
"size": 50
}

Query string queries are not analyzed and but match queries are analyzed.