# Multiple analyzers for dynamic template mapping

**URL:** <https://discuss.elastic.co/t/multiple-analyzers-for-dynamic-template-mapping/156560>\
**Category:** Elasticsearch\
**Created:** [November 14, 2018, 12:42am UTC](https://discuss.elastic.co/t/multiple-analyzers-for-dynamic-template-mapping/156560 "2018-11-14T00:42:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jango\_Mango](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@Jango\_Mango](https://discuss.elastic.co/u/Jango_Mango)\
**Post date:** [November 14, 2018, 12:42am UTC](https://discuss.elastic.co/t/multiple-analyzers-for-dynamic-template-mapping/156560/1 "2018-11-14T00:42:11Z")

</div>

Hi,

Is it possible to set multiple analyzers to a single dynamic template mapping?  
Currently, I'm only able to add single custom analyzer to all string fields

Eg:  
{  
"mappings": {  
"\_doc": {  
"dynamic\_templates": [  
{  
"string\_template": {  
"match\_mapping\_type": "string",  
"match": "\*",  
"mapping": {  
"type": "text",  
"analyzer": "customAnalyzer1"  
}  
}  
}  
]  
}  
}  
}

I'd like to add multiple analyzers like customAnalyzer1, customAnalyzer2 etc for each of the fields found in the document.

Thanks,

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [November 14, 2018, 8:09am UTC](https://discuss.elastic.co/t/multiple-analyzers-for-dynamic-template-mapping/156560/2 "2018-11-14T08:09:32Z")

</div>

Hi,

Yes you can ! In the template you have to add a section:

```
"settings": {
	"analysis": {
		"analyzer": {
			"customAnalyzer1": {
				"type": "custom",
				"tokenizer": "standard",
				"filter": [
					"lowercase",
					"asciifolding",
					"trim"
				]
			},
			"default": {
				"type": "custom",
				"tokenizer": "standard",
				"filter": [
					"lowercase",
					"asciifolding",
					"trim",
					"elision",
					"synonyms"
				]
			},

```

And in the field you can specify the analyzer you want

```
				"contact": {
				"type": "text",
				"analyzer": "customAnalyzer1"
			},

```

You can have a default, customAnalyzer1, customAnalyzer2, ...

Enjoy,  
Xavier

---

<div class="post-metadata">

**Author:** ![Jango\_Mango](https://avatars.discourse-cdn.com/v4/letter/j/e68b1a/32.png) [@Jango\_Mango](https://discuss.elastic.co/u/Jango_Mango)\
**Post date:** [November 14, 2018, 11:01pm UTC](https://discuss.elastic.co/t/multiple-analyzers-for-dynamic-template-mapping/156560/3 "2018-11-14T23:01:53Z")

</div>

Hi @xavierfacq,

Thanks for your reply. Your solution works for a object with defined fields. However, in my case, I'm passing in a dynamic C# object and I would like each of the string fields in that object to be analyzed by multiple analyzers while indexing.

I do have an object mapping (for a defined object) with multiple analyzers as show in the attached screenshot.

![es-object-mapping](https://us1.discourse-cdn.com/elastic/original/3X/5/b/5b0e9e66c76edea095f34ea020345b35dbff2989.png)

I would like to do similar mapping for a dynamic object (on all string fields). Since, I do not know the field names before hand, how can I accomplish this with dynamic templates?

Currently, I'm setting my dynamic templates as attached below:

![es-dynamic-mapping](https://us1.discourse-cdn.com/elastic/original/3X/c/b/cb5e897ecb1bed44b57b0bebb952dda3951147bd.png)

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 12, 2018, 11:01pm UTC](https://discuss.elastic.co/t/multiple-analyzers-for-dynamic-template-mapping/156560/4 "2018-12-12T23:01:59Z")

</div>

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