我有弹性搜索索引,名称为,清除,类型为它包含名为title的字段。我使用river插件创建了这个索引/类型。我使用以下api更改了标题字段的映射。
PUT clear/positionTemplate/_mapping
{
"mappings": {
"positionTemplate": {
"properties": {
"title": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}提交的标题包含以下值:
"Java开发人员“
"C开发者“
"Ruby开发人员“
"Java QA“
"Ruby QA“
"Java开发“
运行以下查询时,排序不正确。
{
"sort" : [{
"title" : {"order":"desc"}
}],
"fields" : [ "title"]
}产出如下:
{
"_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
}这是错误的。有人能指点我怎么改正吗?
发布于 2020-07-30 14:51:07
您需要重新映射字段。
示例:
{
"<field name>": {
"type" "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}然后,在排序方面,您需要指定“关键字”。
示例:
GET <index>/_search
{
"sort": [
{
"<field name>.keyword": {
"order": "asc"
}
}
]
}https://stackoverflow.com/questions/22552973
复制相似问题