Hi guys, sorry i have another question but this time concerning the sorting of a request.
Considering this mapping
{
"sample_data": {
"mappings": {
"properties": {
"title": {
"properties": {
"fr": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"nl": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"poly": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
The restrictions here are if the poly
field is set, the fr
and nl
must be empty. But if the fr
is set then the nl
must be set and the poly
must be empty.
The issue here is when i try to sort on the title
i need to use the poly
when it is set or the fr
/nl
depending on the user language.
How can i do that ?
I tried the multiple sort but when the poly is empty it use null and not the fr/nl value
{
"query": {
"query_string": {
"query": "**",
"fields": ["title.poly", "title.fr"]
}
},
"sort": [{"title.poly.keyword": {"order": "desc"}}, {"title.fr.keyword": {"order": "desc"}}, {"title.nl.keyword": {"order": "desc"}}],
"_source": ["title"]
}
[
{
"_index": "sample_data",
"_type": "_doc",
"_id": "elem0",
"_version": 2,
"_score": null,
"_source": {
"title": {
"poly": "Mi Casa"
}
},
"sort": [
"Mi Casa",
null,
null
]
},
{
"_index": "sample_data",
"_type": "_doc",
"_id": "elem1",
"_version": 1,
"_score": null,
"_source": {
"title": {
"fr": "test with fr",
"nl": "test with nl"
}
},
"sort": [
null,
"test with fr",
"test with nl"
]
}
]