Contitional Analyzer

This filter:
https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-condition-tokenfilter.html

I would like to apply the german stemmer if doc['lang'] == 'de'

{
  "settings": {
    "analysis": {
      "analyzer": {
        "default": {
          "tokenizer" : "standard",
          "filter" : [ "german_condition" ]
        }
      },
      "filter" : {
        "german_condition" : {
            "type" : "condition",
            "filter" : [ "lowercase" ],
            "script" : {
                "source" : "doc['lang'] == 'de'"  
            }
         }
      }
    }
  }
}

Error:
Variable [doc] is not defined.

This there a change to apply a conditional stemming filter?

Hello @doublemax

Seems that "doc" variable/context used in searches doesn't apply to the analyzer context.

In the following documentation you have the list of allowed variables for this context:
https://www.elastic.co/guide/en/elasticsearch/painless/7.2/painless-analysis-predicate-context.html

I hope this helps :slight_smile:

1 Like

Analyzers can be used at index or search time (most of the time same analyzer is used in both cases, with few exceptions). Now, at search time you analyze user input, not document field value and there's no lang.

You shouldn't use conditional filters but instead define multiple analyzers for the languages you have, define one field per language and index the values to its language fields (like value of title to title_de if lang == "de"):

https://www.elastic.co/guide/en/elasticsearch/guide/2.x/one-lang-fields.html

1 Like

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