# Contitional Analyzer

**URL:** <https://discuss.elastic.co/t/contitional-analyzer/189211>\
**Category:** Elasticsearch\
**Created:** [July 6, 2019, 3:30pm UTC](https://discuss.elastic.co/t/contitional-analyzer/189211 "2019-07-06T15:30:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![doublemax](https://avatars.discourse-cdn.com/v4/letter/d/8e7dd6/32.png) [@doublemax](https://discuss.elastic.co/u/doublemax)\
**Post date:** [July 6, 2019, 3:30pm UTC](https://discuss.elastic.co/t/contitional-analyzer/189211/1 "2019-07-06T15:30:50Z")

</div>

This filter:  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-condition-tokenfilter.html](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'`

```auto
{
  "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?

---

<div class="post-metadata">

**Author:** ![Juanma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/juanma/32/49076_2.png) [@Juanma](https://discuss.elastic.co/u/Juanma)\
**Post date:** [July 6, 2019, 3:51pm UTC](https://discuss.elastic.co/t/contitional-analyzer/189211/2 "2019-07-06T15:51:18Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/painless/7.2/painless-analysis-predicate-context.html)

I hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![telendt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/telendt/32/3416_2.png) [@telendt](https://discuss.elastic.co/u/telendt)\
**Post date:** [July 6, 2019, 8:54pm UTC](https://discuss.elastic.co/t/contitional-analyzer/189211/3 "2019-07-06T20:54:21Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/guide/2.x/one-lang-fields.html)

---

<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:** [August 3, 2019, 8:54pm UTC](https://discuss.elastic.co/t/contitional-analyzer/189211/4 "2019-08-03T20:54:45Z")

</div>

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