# Use an analyzer and a normalizer at the same time on the same field?

**URL:** https://discuss.elastic.co/t/use-an-analyzer-and-a-normalizer-at-the-same-time-on-the-same-field/252356
**Category:** Elasticsearch
**Created:** [October 16, 2020, 1:46pm UTC](https://discuss.elastic.co/t/use-an-analyzer-and-a-normalizer-at-the-same-time-on-the-same-field/252356 "2020-10-16T13:46:37Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Nicolas\_Rey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_rey/32/47284_2.png) [@Nicolas\_Rey](https://discuss.elastic.co/u/Nicolas_Rey)
#### Post date: [October 16, 2020, 1:46pm UTC](https://discuss.elastic.co/t/use-an-analyzer-and-a-normalizer-at-the-same-time-on-the-same-field/252356/1 "2020-10-16T13:46:37Z")

</div>

Hi,

for some reason, if need to query (prefix) with an insensitive case on a text field, but I would like to keep the advantage of the tokenisation made by the default Analyzer on the same field, is it possible ?

Example  
My indexed field (let's say three cases from input)  
"productSearchName" : "best white chocolate"  
"productSearchName" : "Best White Chocolate"  
"productSearchName" : "BEST WhItE ChocolatE"

If I apply the standard Analyzer, the produced tokens will be  
["best","white","chocolate"] for three syntax, but how to perform a Prefix query (start with "best white") ? Using the productSearchName.Keyword is impossible since the sensitive case.  
However I can perform match query on any part of the indexed tokens.

If I apply a Normalizer like this one

```auto
      "analysis": {
        "normalizer": {
          "case_insensitive": {
            "filter": [
              "lowercase"
            ],
            "type": "custom"
          }
        }

```

then for the same productSearchName input, I 'll get only one token ["best white chocolate"] which'll allow me to perform case insensitive prefix query, but now I can't easily perform a match query, I need to use a wildcard instead.

Well can someone tell me if both an Analyser and a Normalizer can be used by the same field producing at the same time the tokens ["best","white","chocolate"] and ["best white chocolate"] allowing me to keep the power of match query (no wildcard then) and perform case insensitive prefix query at the same time ?

Many thanks

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [October 16, 2020, 2:03pm UTC](https://discuss.elastic.co/t/use-an-analyzer-and-a-normalizer-at-the-same-time-on-the-same-field/252356/2 "2020-10-16T14:03:01Z")

</div>

Side note: A [normalizer](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/normalizer.html) only works on keyword fields, so I do not think that this is an option here.

First, you may want to take a look at [multi fields](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/multi-fields.html) allowing you to index a single field in different ways in Elasticsearch.

And, just as another point to read about: There is a dedicated [search as you type](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/search-as-you-type.html) field type that could help your use-case.

Hope that helps to get started!

---

<div class="post-metadata">

### Author: ![Nicolas\_Rey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_rey/32/47284_2.png) [@Nicolas\_Rey](https://discuss.elastic.co/u/Nicolas_Rey)
#### Post date: [October 16, 2020, 2:19pm UTC](https://discuss.elastic.co/t/use-an-analyzer-and-a-normalizer-at-the-same-time-on-the-same-field/252356/3 "2020-10-16T14:19:19Z")

</div>

@spinscale

thanks for your quick reply, well I use C# Nest lib with the AutoMap() method which give by default for all "string" fields a "text" type and a keyword.

```
    "stringTypeField": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    }

```

Is it possible to have such mapping for a field (standard Analyzer for text and normalizer for keyword) ?

```
    "productType": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "normalizer": "case_insensitive"
        }
      }
    }

```

I'll have a look at search\_as\_you\_type which may as you say solve my problem!

---

<div class="post-metadata">

### Author: ![Nicolas\_Rey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_rey/32/47284_2.png) [@Nicolas\_Rey](https://discuss.elastic.co/u/Nicolas_Rey)
#### Post date: [October 16, 2020, 2:51pm UTC](https://discuss.elastic.co/t/use-an-analyzer-and-a-normalizer-at-the-same-time-on-the-same-field/252356/4 "2020-10-16T14:51:15Z")

</div>

@spinscale  
The **search\_as\_you\_type** mapping is awesome!! Combining best of two worlds.  
and @abdon told me about v7.10 which'll allows to perform prefix queries on Keyword with a case insensitive parameter (no more Normalizer, "just" for that)

Both of you made my day, thank you very much guys 🙂

---

<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: [November 13, 2020, 2:51pm UTC](https://discuss.elastic.co/t/use-an-analyzer-and-a-normalizer-at-the-same-time-on-the-same-field/252356/5 "2020-11-13T14:51:24Z")

</div>

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