# Analyzer selection on multi-field

**URL:** <https://discuss.elastic.co/t/analyzer-selection-on-multi-field/17187>\
**Category:** Elasticsearch\
**Created:** [April 24, 2014, 9:32pm UTC](https://discuss.elastic.co/t/analyzer-selection-on-multi-field/17187 "2014-04-24T21:32:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy\_McLain](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Jeremy\_McLain](https://discuss.elastic.co/u/Jeremy_McLain)\
**Post date:** [April 24, 2014, 9:32pm UTC](https://discuss.elastic.co/t/analyzer-selection-on-multi-field/17187/1 "2014-04-24T21:32:18Z")

</div>

I'm trying to index a single field three different ways depending on the  
language of the text. I'm using field to determine the analyzer for the  
primary sub-field using the "\_analyzer" field. I set this analyzer in the  
document based on the language of the document. The "secondary" sub-field  
uses the "simple" analyzer. The third sub-field is called "bigram". I want  
the system to use the custom "word\_bigram" analyzer if it the language of  
the document uses whitespace between words, otherwise I want it to use the  
"character\_bigram" analyzer (e.g., Chinese).

I can't figure out how to specify the analyzer for this third field when  
the document is added. My only idea right now is to break the bigram  
sub-field out of the multi-field into two separate fields. Only one of them  
would be included in the document depending on the language. Depending on  
the answer of my other question[https://groups.google.com/forum/#!topic/elasticsearch/UHpw50LLndY](https://groups.google.com/forum/#!topic/elasticsearch/UHpw50LLndY)I'm not crazy about this idea because this may require me to store the  
contents of this field 3 to 4 times.

"body\_word\_bigram": {  
"type": "string",  
"store": true,  
"analyzer": "word\_bigram",  
"boost": 2.0  
},  
"body\_char\_bigram":{  
"type": "string",  
"store": true,  
"analyzer": "char\_bigram",  
"boost": 2.0  
}

I've included the relevant portions of my schema below.

Settings:  
{  
"text\_document": {  
"analysis": {  
"analyzer": {  
"word\_bigram": {  
"type": "custom",  
"tokenizer": "standard",  
"filter": ["lowercase", "truncate\_5", "word\_bigram"]  
},  
"char\_bigram": {  
"type": "custom",  
"tokenizer": "pattern",  
"filter": ["lowercase", "char\_bigram"]  
}  
},  
"filter": {  
"truncate\_5": {  
"type": "truncate",  
"length": 5  
},  
"word\_bigram": {  
"type": "shingle",  
"min\_shingle\_size": 2,  
"max\_shingle\_size": 2,  
"output\_unigrams": false  
},  
"char\_bigram": {  
"type": "nGram",  
"min\_gram": 2,  
"max\_gram": 2  
}  
}  
}  
}  
}

Mapping:  
{  
"text\_document": {  
"\_analyzer": {  
"path": "analyzer"  
},  
"properties": {  
"body": {  
"type": "string",  
"store": true,  
"fields": {  
"secondary": {  
"type": "string",  
"analyzer": "simple"  
},  
"bigram": {  
"type": "string",  
"analyzer": "?",  
"boost": 2.0  
}  
}  
},  
"analyzer": {  
"type": "string",  
"store": "true",  
"index": false  
}  
}  
}  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/825ae036-597a-484d-a94e-95a5daeaad51%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/825ae036-597a-484d-a94e-95a5daeaad51%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jeremy\_McLain](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Jeremy\_McLain](https://discuss.elastic.co/u/Jeremy_McLain)\
**Post date:** [April 30, 2014, 8:06pm UTC](https://discuss.elastic.co/t/analyzer-selection-on-multi-field/17187/2 "2014-04-30T20:06:29Z")

</div>

Ideas anyone?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/63a1b38e-7f80-41d8-8b5a-e16cdb3c2608%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/63a1b38e-7f80-41d8-8b5a-e16cdb3c2608%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:32am UTC](https://discuss.elastic.co/t/analyzer-selection-on-multi-field/17187/3 "2017-07-06T01:32:23Z")

</div>


