# Elasticsearch analyzer

**URL:** <https://discuss.elastic.co/t/elasticsearch-analyzer/76726>\
**Category:** Elasticsearch\
**Created:** [February 28, 2017, 7:02am UTC](https://discuss.elastic.co/t/elasticsearch-analyzer/76726 "2017-02-28T07:02:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greentea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/greentea/32/15924_2.png) [@Greentea](https://discuss.elastic.co/u/Greentea)\
**Post date:** [February 28, 2017, 7:02am UTC](https://discuss.elastic.co/t/elasticsearch-analyzer/76726/1 "2017-02-28T07:02:52Z")

</div>

Hi!  
I want to know is there any method that allow one field use more than one analyzer?

Here is an example, I got an index call **index 1** , and a type call **product**.

under product there are different field like (product\_name, brand\_name etc.)

And there are there analyzer call **Chinese analyzer** , **English analyzer** and **stop-word analyzer**

let say when i do searching, the product\_name is going to be search, and search result follow under the above there analyzer?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [February 28, 2017, 8:22am UTC](https://discuss.elastic.co/t/elasticsearch-analyzer/76726/2 "2017-02-28T08:22:02Z")

</div>

Hi @Greentea,

you can use [multi-fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html) for that. Here is an example that uses multiple analyzers and uses Elasticsearch 5 syntax. I specified the standard analyzer explicitly just for demonstration; it is the implicit default:

```auto
PUT my_index
{
   "mappings": {
      "product": {
         "properties": {
            "product_name": {
               "type": "text",
               "analyzer": "standard",
               "fields": {
                  "stop": {
                     "type": "text",
                     "analyzer": "stop"
                  },
                  "en": {
                     "type": "text",
                     "analyzer": "english"
                  }
               }
            }
         }
      }
   }
}

```

You can then refer to the field as `product_name` and the subfields as `product_name.stop` and `product_name.en`. I also recommend the section [Getting Started with Languages](https://www.elastic.co/guide/en/elasticsearch/guide/current/language-intro.html) in the Definitive Guide.

Daniel

---

<div class="post-metadata">

**Author:** ![Greentea](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/greentea/32/15924_2.png) [@Greentea](https://discuss.elastic.co/u/Greentea)\
**Post date:** [February 28, 2017, 8:43am UTC](https://discuss.elastic.co/t/elasticsearch-analyzer/76726/3 "2017-02-28T08:43:23Z")

</div>

Thank you @danielmitterdorfer for your suggestion but I am using the multi-fields already.  
Here I want to make some explanation first.  
Since my data are mixed with **Chinese** and **English name**.  
And I have to support **simple Chinese** , **traditional Chinese** and **English search**. So, I decided to convert the simple Chinese to traditional Chinese first (which I used a custom analyzer call " **stcn**" ), and then go for searching.  
Also, I need to support **auto complete** , and I used the guide of auto complete example (the analyzer trigram and reverse ).  
recently, I need to add the **stop word** and **synonym** function in elasticsearch (so i created two new analyzer call stop and syno).

And there a problem comes out, I found that the search doesn't support multi analyzer (or I don't how to write the mapping.)

**Can you explain more about using multi-field ?**

Here is my index setting and mapping

```
{
  "settings": {
    "index": {
    "analysis": {
    "analyzer": {
      "trigram": {
        "type": "custom",
        "tokenizer": "standard",
        "filter": [
          "standard",
          "shingle",
          "uppercase"
        ]
      },
      "reverse": {
        "type": "custom",
        "tokenizer": "standard",
        "filter": [
          "standard",
          "reverse"
        ]
      },
      "cn": {
        "type": "custom",
        "tokenizer": "icu"
      },
      "stcn": {
        "type": "custom",
        "tokenizer": "stconvert"
      },
      "stop": {
        "type": "custom",
        "tokenizer": "icu",
        "filter": [
          "my_stop_en",
          "my_stop_cn"
        ]
      },
      "syno":{
        "type": "custom",
        "tokenizer": "standard",
        "filter": [
          "synonym"
        ]
      }
    },
    "tokenizer": {
      "icu": {
        "type": "icu_tokenizer"
      },
      "stconvert": {
        "type": "stconvert",
        "delimiter": "/",
        "keep_both": false,
        "convert_type": "s2t"
      }
    },
    "filter": {
      "shingle": {
        "type": "shingle",
        "min_shingle_size": 2,
        "max_shingle_size": 3
      },
      "synonym": {
        "type": "synonym",
        "synonyms_path": "syno/synonym.txt"
      },
      "my_stop_en": {
        "type": "stop",
        "stopwords_path": "stopword/english.txt"
      },
      "my_stop_cn": {
        "type": "stop",
        "stopwords_path": "stopword/chinese.txt"
      }
    }
  }
 }
}

"mappings": {
      "product": {
         "properties": {
        "display_name": {
          "type": "text",
          "include_in_all": true,
      "fields": {
        "stcn": {
          "type": "text",
          "analyzer": "stcn"
        },
        "cn": {
          "type": "text",
          "analyzer": "cn"
        },
        "trigram": {
          "type": "text",
          "analyzer": "trigram"
        },
        "reverse": {
          "type": "text",
          "analyzer": "reverse"
        },
        "stop": {
          "type": "text",
          "analyzer": "stop"
        },
        "syno":{
          "type": "text",
          "analyzer": "syno"
        }
      }
    }
```

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [February 28, 2017, 9:23am UTC](https://discuss.elastic.co/t/elasticsearch-analyzer/76726/4 "2017-02-28T09:23:25Z")

</div>

Hi @Greentea,

your mapping looks fine. The section [One Language per Field](https://www.elastic.co/guide/en/elasticsearch/guide/current/one-lang-fields.html) should basically answer your questions.

If you want to use multi-fields in searches, you can use a [multi-match query](https://www.elastic.co/guide/en/elasticsearch/reference/master/query-dsl-multi-match-query.html) but you'll need to experiment which settings are best for your use-case. Here is a simple example based on your mapping:

```auto
GET /my_index/product/_search
{
   "query": {
      "multi_match": {
         "query": "Tom and Jerry",
         "fields": [
            "display_name",
            "display_name.*"
         ],
         "type": "most_fields"
      }
   }
}

```

`display_name.*` refers to all your sub-fields. If you want to include only specific ones you can spell out the name, e.g. `display_name.reverse`.

A minor and unrelated suggestion: You have so much customizations in your mappings that I don't think you need the `_all` field so you should check if you can disable it to save a bit of disk space (see [docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/mapping-all-field.html)).

Daniel

---

<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 28, 2017, 9:23am UTC](https://discuss.elastic.co/t/elasticsearch-analyzer/76726/5 "2017-03-28T09:23:25Z")

</div>

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