How to filter out a few inner objects from search query results

Hi,

I have the following schema and two documents and a search query on them. I want to know how can I only display specific language's names and descriptions in each of my search result. For example in the query result for below query, I get all the names and descriptions in all languages. But if I pass a locale as 'fr' I would like names and descriptions only in french. Not in any other languages.
Thanks,

PUT /product/
{

"mappings": {
    "productTypeA":{
        "dynamic": "strict", 
        "properties":{
            "id": { "type": "keyword"  }, 
            "model": { "type": "keyword"}, 
            "version": { "type": "keyword" },  
            "launchDate":  { "type":   "date", 
                "format": "yyyyMMdd'T'HHmmss.SSSZ",
                "fields": {
                    "keyword": { 
                    "type": "keyword"
                    }
                }
            }, 
            "role" :{"type": "keyword" },
            "updatedBy":{"type": "keyword" },
            "names": { "type": "object",
                                "properties":{
                                  "locale":{"type":"keyword"},
                                  "value":{"type":"keyword"}
                                }},
                    "descriptions": { "type": "object",
                                "properties":{
                                  "locale":{"type":"keyword"},
                                  "value":{"type":"keyword"}
                                }}
        }
    }
}

}

POST /product/productTypeA/1
{
"id":"1",
"model":"modelA",
"version":"1.0",
"launchDate": "20190924T175212.057+0000",
"updatedBy":"m1",
"role": ["role1", "role2"],
"names":[{"locale":"en", "value":"product one"}, {"locale":"fr", "value":"produit un"},
{"locale":"de", "value": "Produkt eins"}],
"descriptions":[{"locale":"en", "value":"product one description"}, {"locale":"fr", "value":"description du produit un"},
{"locale":"de", "value": "Produkt eins Beschreibung"}]
}

POST /product/productTypeA/2
{
"id":"2",
"model":"modelB",
"version":"1.0",
"launchDate": "20190924T175212.057+0000",
"updatedBy":"m1",
"role": ["role1"],
"names":[{"locale":"en", "value":"product two"}, {"locale":"fr", "value":"produit deux"},
{"locale":"de", "value": "Produkt zwei"}],
"descriptions":[{"locale":"en", "value":"product two description"}, {"locale":"fr", "value":"description du produit deux"},
{"locale":"de", "value": "Produkt zwei Beschreibung"}]
}

GET /product/productTypeA/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"model": "modelA"
}
},
{
"bool": {
"should": [
{
"bool": {
"must_not": {
"exists": {
"field": "role"
}
}
}
},
{
"term": {
"role": "role2"
}
}
]
}
}
]
}
}

}

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