Multiple analyzers for dynamic template mapping

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,

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

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

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

Thanks,

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