# Multilingual search and retrieval of a translated field

**URL:** <https://discuss.elastic.co/t/multilingual-search-and-retrieval-of-a-translated-field/318683>\
**Category:** Elasticsearch\
**Created:** [November 10, 2022, 6:41pm UTC](https://discuss.elastic.co/t/multilingual-search-and-retrieval-of-a-translated-field/318683 "2022-11-10T18:41:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChristopherHS](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@ChristopherHS](https://discuss.elastic.co/u/ChristopherHS)\
**Post date:** [November 10, 2022, 6:41pm UTC](https://discuss.elastic.co/t/multilingual-search-and-retrieval-of-a-translated-field/318683/1 "2022-11-10T18:41:06Z")

</div>

Hello,

I have the following mapping:

```json
{
  "settings": {
    "analysis": {
      "analyzer": {
        "en_stopwords": {
          "type": "standard",
          "stopwords": "_english_"
        },
        "de_stopwords": {
          "type": "standard",
          "stopwords": "_german_"
        },
        "fr_stopwords": {
          "type": "standard",
          "stopwords": "_french_"
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      },
      "_translations": {
        "properties": {
          "de": {
            "properties": {
              "locale": {
                "type": "text",
                "index": false
              },
              "title": {
                "type": "text"
              }
            }
          },
          "fr": {
            "properties": {
              "locale": {
                "type": "text",
                "index": false
              },
              "title": {
                "type": "text"
              }
            }
          }
        }
      }
    }
  }
}

```

I can't do a global search for titles in the `_translations` property like:

```json
GET _search
{
  "query": {
    "multi_match": {
      "query": "My Search",
      "fields": ["title", "_translations.*.title"]
    }
  }
}

```

We have a dozen translations, do we have to list each field one by one like this:

```json
GET _search
{
  "query": {
    "multi_match": {
      "query": "My Search",
      "fields": [
        "title",
        "_translations.fr.title",
        "_translations.de.title"
      ]
    }
  }
}

```

We also have another problem, when the language is `English`, we display the `title` directly but when it is for example `French`, is it possible to replace the `value` of the `title` field by that of `_translations.fr.title` at the time of data retrieval.

Thanks for your help.

---

<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:** [November 11, 2022, 3:11pm UTC](https://discuss.elastic.co/t/multilingual-search-and-retrieval-of-a-translated-field/318683/2 "2022-11-11T15:11:03Z")

</div>

Hi.

> [@ChristopherHS](#):
>
> I can't do a global search for titles in the `_translations` property like:

Maybe [Query string](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-top-level-params) helps you:

```auto
{
  "query": {
    "query_string": {
      "fields": ["title", "_translations.*.title"],
      "query": "aaa"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![ChristopherHS](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@ChristopherHS](https://discuss.elastic.co/u/ChristopherHS)\
**Post date:** [November 11, 2022, 6:05pm UTC](https://discuss.elastic.co/t/multilingual-search-and-retrieval-of-a-translated-field/318683/3 "2022-11-11T18:05:55Z")

</div>

Hi @RabBit_BR,

Thank you for your answer.

Finally for the search, the initial code worked, I had a problem with the registered mapping.

```auto
GET _search
{
  "query": {
    "multi_match": {
      "query": "My Search",
      "fields": ["title", "_translations.*.title"]
    }
  }
}

```

I also found the solution to update the `title` field with the translated version.  
I pass the locale of the translated field that I want to retrieve.

```auto
GET videos/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "My Search",
            "fields": ["title"]
          }
        }
      ]
    }
  },
  "script_fields": {
    "title": {
      "script": {
        "source": "field('_translations.'+ params.get('locale') +'.title').get('')", 
        "params": {
          "locale": "de"
        }
      }
    }
  }
}

```

---

<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:** [December 9, 2022, 6:06pm UTC](https://discuss.elastic.co/t/multilingual-search-and-retrieval-of-a-translated-field/318683/4 "2022-12-09T18:06:40Z")

</div>

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