Hi all,
so here's the thing: we have some products that have their name
localized in several languages. The name is defined in Elasticsearch
as following:
===
name: {
de: "some german text",
en: "some english text",
nl: "some dutch text"
}
It all works good - if I have to search I search not in the "name"
field, but in "name.nl" or "name.en" depending on the chosen locale on
the frontend.
My question is: is this the right way to handle localization?
Also, the highlighting doesn't work. I tried setting the highlighting
with the Java API as:
===
searchRequestBuilder.addHighlightedField("_source.name[en]");
searchRequestBuilder.addHighlightedField("name[en]");
searchRequestBuilder.addHighlightedField("name");
searchRequestBuilder.addHighlightedField("name.en");
searchRequestBuilder.addHighlightedField("_source.name.en");
searchRequestBuilder.setHighlighterPreTags("");
searchRequestBuilder.setHighlighterPostTags("");
And as you can see I have specified different combinations, but I
never receive the results surrounded by the 'b' tag. I know that the
field must be declared as stored in the mapping, and that is exactly
what I tried.
-
I tried to setup "name" as stored, and then here's how my mapping
looked like
===
{"myproduct":{"properties":{"picture":{"type":"string"},"price":
{"type":"string"},"description":{"dynamic":"true","properties":{"en":
{"type":"string"}}},"name":
{"store":"yes","type":"string"},"availableSizes":
{"type":"string"},"en":{"type":"string"}}}}
=== -
Then I tried to "name.en", and again the mapping:
===
{"myproduct":{"properties":{"picture":{"type":"string"},"price":
{"type":"string"},"description":{"dynamic":"true","properties":{"en":
{"type":"string"}}},"name":{"dynamic":"true","properties":{"en":
{"type":"string"}}},"availableSizes":{"type":"string"},"name.en":
{"store":"yes","type":"string"},"brandName":{"type":"string"},"url":
{"type":"string"},"pk":{"type":"string"},"availableColors":
{"type":"string"}}}} -
The "name[en]", and here's the mapping:
===
{"myproduct":{"properties":{"picture":{"type":"string"},"price":
{"type":"string"},"description":{"dynamic":"true","properties":{"en":
{"type":"string"}}},"name":{"dynamic":"true","properties":{"en":
{"type":"string"}}},"availableSizes":{"type":"string"},"brandName":
{"type":"string"},"url":{"type":"string"},"pk":
{"type":"string"},"name[en]":
{"store":"yes","type":"string"},"availableColors":{"type":"string"}}}}
=== -
Last I tried setting only "en" as stored, and here's the mapping:
===
{"myproduct":{"properties":{"picture":{"type":"string"},"price":
{"type":"string"},"description":{"dynamic":"true","properties":{"en":
{"type":"string"}}},"name":{"dynamic":"true","properties":{"en":
{"type":"string"}}},"availableSizes":{"type":"string"},"en":
{"store":"yes","type":"string"},"brandName":{"type":"string"},"url":
{"type":"string"},"pk":{"type":"string"},"availableColors":
{"type":"string"}}}}
===
After each of these I tried to search for something that gives result,
and I got no highlighting.
Does any of you have any idea how can I get a highlighting in my
search results?
Thank you for your time.