I want to know if it is possible to search value in all array elements in a nested Elasticsearch object in one single query? See my situation next:
In ElasticSearch database I've configured a nested object on column name:
$set_index = [
'index' => 'table',
'body' => [
'mappings' => [
'table' => [
'_source' => [
'enabled' => true
],
'properties' => [
"name" => [ // name of column
"type" => "nested"
],
]
]
]
]
];
Then I insert following data (through PHP):
$data1 = array(
'descripotion' => 'Row 1',
'name' => [
'en' => 'First name data',
'ru' => 'Первое имя',
'de' => 'Eins data',
'it' => 'something else',
]
);
$data2 = array(
'descripotion' => 'Row 2',
'name' => [
'en' => 'Second name data',
]
);
And then I query on this data using the POST method through Postman Chrome extension:
POST http://localhost:9200/_search
Body is:
{
"query":{
"nested": {
"path": "name",
"query": {
"bool": {
"must": [
{ "match": { "name.en": "First" }}
]
}
}
}
}
}
This is working perfectly. In above query - I am querying data based on English translation in column name.
So if I wanted to search using the Russian language, the code would have been following:
{ "match": { "name.ru": "First" }}
Now, what I want to do - is to query on all translations at the same time (there can be 1 to 100 languages provided). Something like:
{ "match": { "name.*": "First" }}
question - is That possible, using my current config? If not with current config, then how? I know that if I convert
namecolumn back to normal type (instead ofnested) - then it becomes possible, as all translations are concentrated into a singlestringtype value. But in that case - i am loosing the possibility to be selective! I want both :) Preferably, without data duplication.question - if I am searching for all translations at the same time - is it possible to prioritize one language over another? So if word
datais in 5 languages - I want the document which containedEnglishsearch result - to be first in the list.