我按照文档 https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-fields.html 为名称字段添加了排序列。不幸的是,它不起作用
这些是步骤:
- 添加索引映射
PUT /staff { "mappings": { "staff": { "properties": { "id": { "type": "string", "index": "not_analyzed" }, "name": { "type": "string", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } } } } } }
- 添加文档
POST /staff/list { "id": 5, "name": "abc" }
- 搜索名称.raw
POST /staff_change/_search { "sort": "name.raw" }
但是,响应中的排序字段返回 null
"_source": {
"id": 5,
"name": "abc"
},
"sort": [
null
]
}
我不知道为什么它不起作用,我无法搜索与此相关的问题文档。有人遇到这个问题吗
提前非常感谢
您的映射不正确。您在索引staff
内创建一个映射staff
,然后在索引staff
内的映射list
下为文档编制索引,该索引有效,但使用动态映射,而不是您添加的映射。最后,您将搜索索引staff
中的所有文档。试试这个:
PUT /staff
{
"mappings": {
"list": {
"properties": {
"id": {
"type": "string",
"index": "not_analyzed"
},
"name": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
然后索引:
POST /staff/list {
"id": 5,
"name": "abc aa"
}
和查询:
POST /staff/list/_search
{
"sort": "name.raw"
}
结果:
"hits": [
{
"sort": [
"abc aa"
]
}
...