# "query\_string" dosen't analyze wildcard queries

**URL:** <https://discuss.elastic.co/t/query-string-dosent-analyze-wildcard-queries/109533>\
**Category:** Elasticsearch\
**Created:** [November 29, 2017, 8:08am UTC](https://discuss.elastic.co/t/query-string-dosent-analyze-wildcard-queries/109533 "2017-11-29T08:08:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Ott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_ott/32/105905_2.png) [@Alexander\_Ott](https://discuss.elastic.co/u/Alexander_Ott)\
**Post date:** [November 29, 2017, 8:08am UTC](https://discuss.elastic.co/t/query-string-dosent-analyze-wildcard-queries/109533/1 "2017-11-29T08:08:11Z")

</div>

Hi,

after upgrade from ES 2.4.4 to ES 5.6.1 the following query dosen't get analyzed by our analyzer

```
{
  "analyzer": {
    "default": {
      "type": "custom",
      "tokenizer": "fesadTokenizer",
      "char_filter": [
        "german_special",
        "strip_multiple_chars"
      ],
      "filter": [
        "asciifolding",
        "lowercase"
      ]
    }
  }

  "query": {
    "bool": {
      "must": [
        {
          "query_string": {
            "query": "*chifffahrt",
            "default_field": "_all",
            "allow_leading_wildcard": true,
            "analyze_wildcard": true
          }
        }
      ]
    }
  }
}

```

I think the reason is [https://github.com/elastic/elasticsearch/commit/14d2b122a1b91ba14fc13fbb103e553cfddd5778#diff-3d1f1c3586dc5fe67e7615030feaecec](https://github.com/elastic/elasticsearch/commit/14d2b122a1b91ba14fc13fbb103e553cfddd5778#diff-3d1f1c3586dc5fe67e7615030feaecec)

After this change the getPossiblyAnalyzedWildcardQuery(indexedNameField, termStr) was removed and the org.apache.lucene.analysis.Analyzer#normalize(java.lang.String, java.lang.String) is used instead.

The defined char\_filter's and token\_filter's dosn't get called which is a problem for us cause we dosn't receive any hits.

Is this behaviour as expected in ES 5.6.1 or is it a bug or configuration error?

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [November 29, 2017, 5:21pm UTC](https://discuss.elastic.co/t/query-string-dosent-analyze-wildcard-queries/109533/2 "2017-11-29T17:21:50Z")

</div>

At least the lowercase and asciifolding filters should be applied. I can't tell about the char filters and you tokenizer since I don't know how they are implemented.

Can you share the output of the following request with both versions?

```auto
GET your_index_name/_validate/query?rewrite=true
{
  "query" : {
    "query_string": {
      "query": "*chifffahrt",
      "default_field": "_all",
      "allow_leading_wildcard": true,
      "analyze_wildcard": true
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Alexander\_Ott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_ott/32/105905_2.png) [@Alexander\_Ott](https://discuss.elastic.co/u/Alexander_Ott)\
**Post date:** [November 30, 2017, 6:44am UTC](https://discuss.elastic.co/t/query-string-dosent-analyze-wildcard-queries/109533/3 "2017-11-30T06:44:30Z")

</div>

The solution is that our own CharFilterFactory which extends org.elasticsearch.index.analysis.AbstractCharFilterFactory also must implement the interface org.elasticsearch.index.analysis.MultiTermAwareComponent which was not the case so far.

Cause org.apache.lucene.analysis.Analyzer#normalize(java.lang.String, java.lang.String) calls org.elasticsearch.index.analysis.CustomAnalyzer#initReaderForNormalization where only CharFilterFactory's which are instanceof MultiTermAwareComponent will be used

```
        @Override
        protected Reader initReaderForNormalization(String fieldName, Reader reader) {
          for (CharFilterFactory charFilter : charFilters) {
            if (charFilter instanceof MultiTermAwareComponent) {
              charFilter = (CharFilterFactory) ((MultiTermAwareComponent) charFilter).getMultiTermComponent();
              reader = charFilter.create(reader);
            }
          }
          return reader;
        }

```

The same applies to the TokenFilterFactory's

```
        @Override
        protected TokenStream normalize(String fieldName, TokenStream in) {
          TokenStream result = in;
          for (TokenFilterFactory filter : tokenFilters) {
            if (filter instanceof MultiTermAwareComponent) {
              filter = (TokenFilterFactory) ((MultiTermAwareComponent) filter).getMultiTermComponent();
              result = filter.create(result);
            }
          }
          return result;
        }
```

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [November 30, 2017, 9:33am UTC](https://discuss.elastic.co/t/query-string-dosent-analyze-wildcard-queries/109533/4 "2017-11-30T09:33:34Z")

</div>

This is correct. Do I get it right that it fixed your issue?

---

<div class="post-metadata">

**Author:** ![Alexander\_Ott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_ott/32/105905_2.png) [@Alexander\_Ott](https://discuss.elastic.co/u/Alexander_Ott)\
**Post date:** [November 30, 2017, 9:50am UTC](https://discuss.elastic.co/t/query-string-dosent-analyze-wildcard-queries/109533/5 "2017-11-30T09:50:52Z")

</div>

Yes this fixed my issue.

Thanks

---

<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:** [December 28, 2017, 9:51am UTC](https://discuss.elastic.co/t/query-string-dosent-analyze-wildcard-queries/109533/6 "2017-12-28T09:51:11Z")

</div>

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