Hi everyone. I have this kind of issue: I have a numeric string field, seperated with dots, like "1.1.2", "11.2.1", and the like. I have a requirement to do sorting by this field, and when I try to sort by that field, it does String sorting. So I should write an analyser, so that here, in this sample, "11.2.1" comes first when 'desc' sorting by this field. I do my mapping and setting this way:
PUT your_index
{
"settings": {
"analysis": {
"analyzer": {
"custom_sort_analyzer": {
"tokenizer": "dot_tokenizer",
"filter": [
"numeric_sort_filter"
]
}
},
"tokenizer": {
"dot_tokenizer": {
"type": "pattern",
"pattern": "\\."
}
},
"filter": {
"numeric_sort_filter": {
"type": "pattern_replace",
"pattern": "(\\d+)",
"replacement": "$1",
"lowercase": true
}
}
}
},
"mappings": {
"properties": {
"your_field": {
"type": "text",
"analyzer": "custom_sort_analyzer",
"fielddata": true
}
}
}
}
But again, getting not correct behavior when I'm doing this kind of sorting :
{
"query": "my_query",
"sort": [
{
"my_field": {
"order": "asc"
}
}
]
}