# How to map two Analyzers to a same field in an index?

**URL:** <https://discuss.elastic.co/t/how-to-map-two-analyzers-to-a-same-field-in-an-index/184248>\
**Category:** Elasticsearch\
**Created:** [June 4, 2019, 8:14pm UTC](https://discuss.elastic.co/t/how-to-map-two-analyzers-to-a-same-field-in-an-index/184248 "2019-06-04T20:14:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gauresh\_chavan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gauresh_chavan/32/42510_2.png) [@gauresh\_chavan](https://discuss.elastic.co/u/gauresh_chavan)\
**Post date:** [June 4, 2019, 8:14pm UTC](https://discuss.elastic.co/t/how-to-map-two-analyzers-to-a-same-field-in-an-index/184248/1 "2019-06-04T20:14:17Z")

</div>

I am indexing the documents from a SQL table and there are two fields 'parent\_sentence' and 'parent\_context' which are primarily used for search.

I am building synonym and 'search-as-you-type'/Partial search on both of those fields. While i am able to build analyzers for the said capabilities, I am unable to get desirable results.

My analyzers are such:

```auto
PUT diabetes/
{
  "settings": {
    "analysis": {
      "filter": {
        "synonym_filter" : {
          "type" : "synonym",
          "synonyms" : "synonyms.txt"
        },
        "autocomplete_filter" : {
          "type": "edge_ngram",
          "min_gram": 4,
          "max_gram": 10
        }
      },
      "analyzer": {
        "synonym_analyzer" : {
        "tokenizer" : "standard",
        "filter" : ["lowercase","synonym_filter"] 
        },
        "autocomplete_analyzer" : {
          "tokenizer" : "standard",
          "filter" : ["lowercase","synonym_filter"] 
        }
      }
    }
  }
}

```

And the corresponding mapping is as follows:

```auto
PUT diabetes/_mapping
{
  "properties": {
    "parent_context" : {
      "type" : "text",
      "analyzer": "autocomplete_analyzer",
      "fields": {
        "syn" : {
          "type" : "text",
          "analyzer" : "synonym_analyzer"
        },
        "keyword" : {
          "type" : "keyword"
        }
      }
    },
  "parent_sentence" : {
   "type" : "text",
   "analyzer": "autocomplete_analyzer",
   "fields": {
     "syn" : {
       "type" : "text",
       "analyzer" : "synonym_analyzer"
       },
      "keyword" : {
          "type" : "keyword"
        }
     }
    }
  }
}

```

When I query 'depre' (i am looking to get results containing word 'depression'), i get the following:  
Query:

```auto
GET diabetes/_search
{
  "query": {
    "match": {
      "parent_context": {
        "query": "depre",
        "analyzer": "standard"
      }
    }
  }
}

```

Result:

```auto
{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : []
  }
}

```

---

<div class="post-metadata">

**Author:** ![CristianoFerreira](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cristianoferreira/32/47529_2.png) [@CristianoFerreira](https://discuss.elastic.co/u/CristianoFerreira)\
**Post date:** [June 5, 2019, 8:41am UTC](https://discuss.elastic.co/t/how-to-map-two-analyzers-to-a-same-field-in-an-index/184248/2 "2019-06-05T08:41:24Z")

</div>

Hi @gauresh_chavan,

You have defined the filter `autocomplete_filter` but you are not using it in any analyzer.

I would suggest to change the `autocomplete_analyzer` analyzer to:

```
"autocomplete_analyzer" : {
    "tokenizer" : "standard",
    "filter" : ["lowercase","autocomplete_filter"] 
}

```

Best Regards

---

<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:** [July 3, 2019, 8:41am UTC](https://discuss.elastic.co/t/how-to-map-two-analyzers-to-a-same-field-in-an-index/184248/3 "2019-07-03T08:41:31Z")

</div>

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