简体   繁体   中英

How to use different analyzers in Elasticsearch depending on document to insert?

My mapping has 4 string fields:

  • "name"
  • "info"
  • "language"
  • "genre"

and 4 custom analyzers:

  • "english_custom_analyzer"
  • "french_custom_analyzer"
  • "spanish_custom_analyzer"
  • "arabic_custom_analyzer"

I want to be able to specify the Analyzer to use when inserting the document using the language field. So If the language is English I want to use the English analyzer for documents field and if the language is French, I want to use the French Analayzer.

I tried to create an extra field called, "language_name_analyzer", populate that field with the analyzer name at insert time and set the analyzer name to "language_name_analyzer". But I get this error:

Cause: org.elasticsearch.index.mapper.MapperParsingException: Analyzer [language_name_analyzer] not found for field [datacontent_onair_title]

Thank you

First of all, I would recommend to reconsider using this feature since it has been removed from the next major release of elasticsearch 2.0.

If you still want to use it, you need to specify the path to the language_name_analyzer field in the mapping:

{
    "type1" : {
        "_analyzer" : {
            "path" : "language_name_analyzer"
        },
        "properties": {
            //// your other fields
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM