I have elastic search index with name clear and type positionTemplate. It contains field called title. I had created this index/type using river jdbc plugin. I had changed mapping of title field using following api.
PUT clear/positionTemplate/_mapping
{
"mappings": {
"positionTemplate": {
"properties": {
"title": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
title filed contains following values :
"Java Developer"
"C Developer"
"Ruby Developer"
"Java QA"
"Ruby QA"
"Java Dev"
while running following query sorting is not proper.
{
"sort" : [{
"title" : {"order":"desc"}
}],
"fields" : [ "title"]
}
output is :
{
"_shards": {
"failed": 0,
"successful": 5,
"total": 5
},
"hits": {
"hits": [
{
"_id": "3",
"_index": "clear",
"_score": null,
"_type": "positionTemplate",
"fields": {
"title": [
"Ruby Developer"
]
},
"sort": [
"ruby"
]
},
{
"_id": "5",
"_index": "clear",
"_score": null,
"_type": "positionTemplate",
"fields": {
"title": [
"Ruby QA"
]
},
"sort": [
"ruby"
]
},
{
"_id": "4",
"_index": "clear",
"_score": null,
"_type": "positionTemplate",
"fields": {
"title": [
"Java QA"
]
},
"sort": [
"qa"
]
},
{
"_id": "15",
"_index": "clear",
"_score": null,
"_type": "positionTemplate",
"fields": {
"title": [
"Java Dev"
]
},
"sort": [
"java"
]
},
{
"_id": "1",
"_index": "clear",
"_score": null,
"_type": "positionTemplate",
"fields": {
"title": [
"Java Developer"
]
},
"sort": [
"java"
]
},
{
"_id": "2",
"_index": "clear",
"_score": null,
"_type": "positionTemplate",
"fields": {
"title": [
"C Developer"
]
},
"sort": [
"developer"
]
}
],
"max_score": null,
"total": 6
},
"timed_out": false,
"took": 2
}
This is wrong. Can somebody guide me how to correct it ?
you need to re map the field.
Example:
{
"<field name>": {
"type" "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
Then on sort propriety, you will need to specify the "keyword".
Example:
GET <index>/_search
{
"sort": [
{
"<field name>.keyword": {
"order": "asc"
}
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With