Multiple analyzers for dynamic template mapping


(Jango Mango) #1

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,


(Xavier Facq) #2

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


(Jango Mango) #3

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.

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:

Thanks,


(system) #4

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