# Searching and filtering i18n terms

**URL:** <https://discuss.elastic.co/t/searching-and-filtering-i18n-terms/36052>\
**Category:** Elasticsearch\
**Created:** [December 1, 2015, 1:37pm UTC](https://discuss.elastic.co/t/searching-and-filtering-i18n-terms/36052 "2015-12-01T13:37:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabrice\_Hong](https://avatars.discourse-cdn.com/v4/letter/f/779978/32.png) [@Fabrice\_Hong](https://discuss.elastic.co/u/Fabrice_Hong)\
**Post date:** [December 1, 2015, 1:37pm UTC](https://discuss.elastic.co/t/searching-and-filtering-i18n-terms/36052/1 "2015-12-01T13:37:21Z")

</div>

Hello,

**tldr;**

How to match and filter localized search with a localized index ?

**long version**

I have an application where the user search must be done in the context of it's language.

In elastic search index, I want documents with both i18n properties and non i18n properties (I want to avoid creating multiple index, one for each language).

The mapping of the document should look like :

'entry': {  
'properties': {  
'name' : {'type': 'string'}, /\* unlocalized properties _/  
'category': { /_ localized properties \*/  
"properties" : {  
"lang\_fr" : {  
"type" : "string"  
},  
"lang\_de" : {  
"type" : "string"  
}  
}  
},  
}  
}

having that, I have two requirements:

1. when doing a search, exclude from search the localized fields that are not concerned by the user language (let's say the user's language is 'fr', I want to exclude 'de' fields from search. How to do this without specifying the entire list of fields I want to search on. To start simple, I tried this but it doesn't work :  
{"query":  
{  
"match": {  
'\*.lang\_fr': full\_text  
}  
}  
}

However, "'categories.lang\_fr': full\_text" works well. But I don't want to maintain the list of fields in the query. I want a general rule like you can do in SolR.

1. when I retrieve my results, I want to filter out all localized fields that doesn't corresponds to my user language. In other words, using the _source filter, I'd like to have all unlocalized fields, exclude all fields starting with "lang_" , but include all fields being 'lang\_fr'. I tried the following but it doesn't work:

{  
"_source": {  
"include": ["", ".lang\_de"],  
"exclude": ["\*.lang_\*"],  
}  
...  
}

the wildcard operator doesn't seems to work. I partially have that I want if I specify "categories.lang\_de", but again, I don't want to maintain the list of fields, I want a generic rule. The include/exclude operation doesn't work as I would like. The only thin that actually work is a query where I specify all languages to excludes for all fields specifically, such as :

{  
"\_source": {  
"exclude": [ "categories.lang\_de", "categories.lang\_en", "categories.lang\_it",  
"another\_field.lang\_de", "catanother\_fieldgories.lang\_en", "another\_field.lang\_it"],  
}  
...  
}

for 'fr' search.

I'm quite surprised I couldn't find anything on google. I see it as a very standard case of i18n applied to elasticsearch. Maybe I'm modelizing i18n the wrong way in ES ?

thank you in advance !

---

<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:** [July 5, 2017, 11:34pm UTC](https://discuss.elastic.co/t/searching-and-filtering-i18n-terms/36052/2 "2017-07-05T23:34:27Z")

</div>


