英文:
Creating an index with multiple sort fields in Elasticsearch 7.17.9
问题
I'm currently learning and still a newbie to Elasticsearch. I'm trying to create an index with multiple sort fields (id, created_at) using the search_after parameter in the Python Elasticsearch Client. Here's the query I've already tried, but I encountered an error:
{
"error" : {
"root_cause" : [
{
"type" : "settings_exception",
"reason" : "Failed to load settings from [{\"index\":[{\"sort.field\":\"created_at\",\"sort.order\":\"asc\"},{\"sort.field\":\"id\",\"sort.order\":\"asc\"}]}]"
}
],
"type" : "settings_exception",
"reason" : "Failed to load settings from [{\"index\":[{\"sort.field\":\"created_at\",\"sort.order\":\"asc\"},{\"sort.field\":\"id\",\"sort.order\":\"asc\"}]}]",
"caused_by" : {
"type" : "illegal_state_exception",
"reason" : "only value lists are allowed in serialized settings"
}
},
"status" : 500
}
请帮我解决这个问题。谢谢!
英文:
Currently I'm learning and still a newbie to Elasticsearch.
I'm trying to create an index with multiple sort fields (id, created_at). My plan is to try using the search_after parameter in the search function from Python Elasticsearch Client.
Here is the query I've already tried:
PUT /my-index
{
"settings": {
"index":[
{
"sort.field": "created_at",
"sort.order": "asc"
},
{
"sort.field": "id",
"sort.order": "asc"
}
]
},
"mappings": {
"properties": {
"id": {
"type": "keyword",
"doc_values": true
},
"name": {
"type": "keyword"
},
"created_at": {
"type": "date"
}
}
}
}
But, I got an error like this:
{
"error" : {
"root_cause" : [
{
"type" : "settings_exception",
"reason" : "Failed to load settings from [{\"index\":[{\"sort.field\":\"created_at\",\"sort.order\":\"asc\"},{\"sort.field\":\"id\",\"sort.order\":\"asc\"}]}]"
}
],
"type" : "settings_exception",
"reason" : "Failed to load settings from [{\"index\":[{\"sort.field\":\"created_at\",\"sort.order\":\"asc\"},{\"sort.field\":\"id\",\"sort.order\":\"asc\"}]}]",
"caused_by" : {
"type" : "illegal_state_exception",
"reason" : "only value lists are allowed in serialized settings"
}
},
"status" : 500
}
Please help me. Thanks in advance!
答案1
得分: 1
你需要这样做:
PUT /my-index
{
"settings": {
"index": {
"sort.field": [ "created_at", "id" ],
"sort.order": [ "asc", "asc" ]
}
},
...
}
英文:
You need to do it like this:
PUT /my-index
{
"settings": {
"index": {
"sort.field": [ "created_at", "id" ],
"sort.order": [ "asc", "asc" ]
}
},
...
答案2
得分: 1
你有一个语法错误,elastic 不知道组合排序顺序。尝试以下内容,
{
"settings": {
"index": {
"sort.field": [
"created_at",
"id"
],
"sort.order": [
"asc",
"asc"
]
}
},
"mappings": {
"properties": {
"id": {
"type": "keyword",
"doc_values": true
},
"name": {
"type": "keyword"
},
"created_at": {
"type": "date"
}
}
}
}
英文:
You have a syntax error, elastic don't know the combined sort order. Try following,
{
"settings": {
"index": {
"sort.field": [
"created_at",
"id"
],
"sort.order": [
"asc",
"asc"
]
}
},
"mappings": {
"properties": {
"id": {
"type": "keyword",
"doc_values": true
},
"name": {
"type": "keyword"
},
"created_at": {
"type": "date"
}
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论