Contitional Analyzer

This filter:

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'"  

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:

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"):

1 Like

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