# \[solved\] Wildcard search with special characters: Differences between ES 1.7 and ES 5.1

**URL:** <https://discuss.elastic.co/t/solved-wildcard-search-with-special-characters-differences-between-es-1-7-and-es-5-1/73720>\
**Category:** Elasticsearch\
**Created:** [February 2, 2017, 4:35pm UTC](https://discuss.elastic.co/t/solved-wildcard-search-with-special-characters-differences-between-es-1-7-and-es-5-1/73720 "2017-02-02T16:35:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mweibel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mweibel/32/15149_2.png) [@mweibel](https://discuss.elastic.co/u/mweibel)\
**Post date:** [February 2, 2017, 4:35pm UTC](https://discuss.elastic.co/t/solved-wildcard-search-with-special-characters-differences-between-es-1-7-and-es-5-1/73720/1 "2017-02-02T16:35:10Z")

</div>

I'm in the process of upgrading a project from ES 1.7 to ES 5.1 and noticed an integration test failing.  
Below is a minimal repro case.

When searching using a wildcard search for "_brö_" I get in both versions the same result. When searching using "_brö{"/)?_" which gets escaped as "_brö\{\\\"\/\)_", I get 2 results in ES 1.7 and no results in ES 5.1.

I searched breaking changes of ES 2.x and ES 5.x but could not find anything related to that. Also searched for new query string search settings which could help in that regard but couldn't find it either.  
If you have any idea what's going on, please let me know 🙂 Thanks.

## Repro case:

### ES 5 index creation

```auto
curl -X PUT 'http://localhost:9200/testwildcard' -d '{
  "mappings": {
    "testwildcard": {
      "properties": {
        "name": {
          "type": "keyword",
          "fields": {
            "search": {
              "type": "text"
            }
          }
        }
      }
    }
  }
}'

```

### ES 1.7 index creation

```auto
curl -XPUT 'http://localhost:9200/testwildcard' -d '{
  "mappings": {
    "testwildcard": {
      "properties": {
        "name": {
          "type": "string",
          "analyzed": "not_analyzed",
          "fields": {
            "search": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}'

```

### Insert data

```auto
curl -XPUT 'http://localhost:9200/testwildcard/testwildcard/1' -d '{
 "name": "Brötchen"
}'

curl -XPUT 'http://localhost:9200/testwildcard/testwildcard/2' -d '{
 "name": "Frischbackbrötchen"
}'

curl -XPUT 'http://localhost:9200/testwildcard/testwildcard/3' -d '{
 "name": "Brot"
}'

```

### works in both ES 1.7 and ES 5.1:

```auto
curl -XPOST 'http://localhost:9200/testwildcard/_search' -d '{
  "explain": true,
  "query": {
    "query_string": {
      "query": "name.search:*brö*",
      "analyze_wildcard": true,
      "default_operator": "AND"
    }
  }
}'

```

### doesn't work in ES 5.1 but works in ES 1.7:

```auto
curl -XPOST 'http://localhost:9200/testwildcard/_search' -d '{
  "explain": true,
  "query": {
    "query_string": {
      "query": "name.search:*brö\\{\\\\\\\"\\/\\)*",
      "analyze_wildcard": true,
      "default_operator": "AND"
    }
  }
}'

```

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [February 3, 2017, 3:24pm UTC](https://discuss.elastic.co/t/solved-wildcard-search-with-special-characters-differences-between-es-1-7-and-es-5-1/73720/2 "2017-02-03T15:24:01Z")

</div>

Maybe it is interesting that `simple_query_string` wildcard search works, with the peculiar symbols.

In `simple_query_string` you can have only prefix search (leading \* is not allowed).

Example

```auto
DELETE /test

PUT /test
{
  "mappings": {
    "testwildcard": {
      "properties": {
        "name": {
          "type": "text",
          "fields": {
            "search": {
              "type": "text"
            }
          }
        }
      }
    }
  }
}

PUT /test/testwildcard/1
{
 "name": "Brötchen"
}

PUT /test/testwildcard/2
{
 "name": "Frischbackbrötchen"
}

PUT /test/testwildcard/3
{
 "name": "Brot"
}

POST /test/_search

POST /test/_search
{
  "explain": true,
  "query": {
    "simple_query_string": {
      "query": "brö*",
      "fields" : ["name.search"],
      "analyze_wildcard": true,
      "default_operator": "AND"
    }
  }
}

POST /test/_search
{
  "explain": true,
  "query": {
    "simple_query_string": {
      "query": "*brö*",
      "fields" : ["name.search"],
      "analyze_wildcard": true,
      "default_operator": "AND"
    }
  }
}

POST /test/_search
{
  "explain": true,
  "query": {
    "simple_query_string": {
      "query": "*brö\\{\\\\\\\"\\/\\)*",
      "fields" : ["name.search"],
      "analyze_wildcard": true,
      "default_operator": "AND"
    }
  }
}

```

All queries give 1 hit (Brötchen).

---

<div class="post-metadata">

**Author:** ![mweibel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mweibel/32/15149_2.png) [@mweibel](https://discuss.elastic.co/u/mweibel)\
**Post date:** [February 3, 2017, 4:03pm UTC](https://discuss.elastic.co/t/solved-wildcard-search-with-special-characters-differences-between-es-1-7-and-es-5-1/73720/3 "2017-02-03T16:03:43Z")

</div>

Thanks for your reply. That's interesting indeed and I can confirm that.

I just tried if it's still working like expected in 2.x and it does indeed. So it seems to be a change between 2.x and 5.x.  
Maybe the lucene upgrade from 5.x to 6.0.0?

[https://lucene.apache.org/core/6\_4\_0/changes/Changes.html#v6.0.0](https://lucene.apache.org/core/6_4_0/changes/Changes.html#v6.0.0)

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 3, 2017, 10:17pm UTC](https://discuss.elastic.co/t/solved-wildcard-search-with-special-characters-differences-between-es-1-7-and-es-5-1/73720/4 "2017-02-03T22:17:16Z")

</div>

It'd be worth raising this on Github, if you haven't already 🙂

---

<div class="post-metadata">

**Author:** ![mweibel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mweibel/32/15149_2.png) [@mweibel](https://discuss.elastic.co/u/mweibel)\
**Post date:** [February 6, 2017, 7:21am UTC](https://discuss.elastic.co/t/solved-wildcard-search-with-special-characters-differences-between-es-1-7-and-es-5-1/73720/5 "2017-02-06T07:21:23Z")

</div>

Didn't yet. Opened one now: [https://github.com/elastic/elasticsearch/issues/22989](https://github.com/elastic/elasticsearch/issues/22989)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 6, 2017, 7:21am UTC](https://discuss.elastic.co/t/solved-wildcard-search-with-special-characters-differences-between-es-1-7-and-es-5-1/73720/6 "2017-03-06T07:21:52Z")

</div>

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