# How to apply the right stopwords langage depending on the field of a document?

**URL:** <https://discuss.elastic.co/t/how-to-apply-the-right-stopwords-langage-depending-on-the-field-of-a-document/313156>\
**Category:** Elasticsearch\
**Created:** [August 29, 2022, 11:41am UTC](https://discuss.elastic.co/t/how-to-apply-the-right-stopwords-langage-depending-on-the-field-of-a-document/313156 "2022-08-29T11:41:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![minikali](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/minikali/32/100559_2.png) [@minikali](https://discuss.elastic.co/u/minikali)\
**Post date:** [August 29, 2022, 11:41am UTC](https://discuss.elastic.co/t/how-to-apply-the-right-stopwords-langage-depending-on-the-field-of-a-document/313156/1 "2022-08-29T11:41:10Z")

</div>

Let's say I have an index of News with many documents of different langages. Users have one search bar to look for the title they desire among the different langages. I don't know which langage the user is typing so I would like to remove stopwords depending on the document langage.

This is how I tried to define my index:

```auto
{
    name: "news",
    mappings: {
      dynamic: false,
      properties: {
        id: { type: "keyword" },
        title: { type: "text" },
        content: { type: "text" },
        lang: { type: "keyword" },
        created_at: { type: "date" },
        updated_at: { type: "date" },
      },
    },
    settings: {
      analysis: {
        analyzer: {
          default: {
            type: "custom",
            tokenizer: "standard",
            filter: ["my_custom_stop_words_filter"],
          },
        },
        filter: {
          my_custom_stop_words_filter: {
            type: "stop",
            stopwords: "_english_",
            script: {
              source: "lang.getText() === 'english'",
            },
          },
        },
      },
    }

```

I want to be able to filter out the right stopwords for every documents depending on the field "lang" of each document. How can I achieve this ?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [August 29, 2022, 4:31pm UTC](https://discuss.elastic.co/t/how-to-apply-the-right-stopwords-langage-depending-on-the-field-of-a-document/313156/2 "2022-08-29T16:31:16Z")

</div>

Hi @minikali

If the user is searching through the browser, you know the language through the browser itself. Is this not possible for you?

Today I do this, I mapped a field for each language and use the specific analyzer for each language.  
Would be like this:

```auto
   "title": {
         "type": "text",
         "fields": {
           "pt-br": {
             "type": "text",
             "analyzer": "brazilian"
           },
           "fr": {
             "type": "text",
             "analyzer": "french"
           },
           "en": {
             "type": "text",
             "analyzer": "english"
           },
       }

```

When I do a search, I know the language because I search the browser and set up the query so that the search is on the field that represents the browser's language.

```auto
                      "multi_match":{
                         "query":"test",
                         "fields":[
                            "description.pt-br",
                            "title.pt-br"
                         ]

```

This works fine with me.

---

<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:** [September 26, 2022, 4:31pm UTC](https://discuss.elastic.co/t/how-to-apply-the-right-stopwords-langage-depending-on-the-field-of-a-document/313156/3 "2022-09-26T16:31:47Z")

</div>

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