启用关键字类型的数字的上升和降序排序(Elasticsearch)
我的任务是按上升和下降顺序排序文档,但是“数字”必须保留在关键字类型中。我阅读了有关类似主题的其他帖子,并试图添加一个“数量”类型整数,但我没有成功,索引崩溃了。我正在将当前配置附加在esmapping.js文件中。
有没有办法修复此esmapping.js文件,以便上升和下降排序有效?
"settings": {
"analysis": {
"analyzer": {
"document_number_analyzer": {
"type": "custom",
"tokenizer": "document_number_tokenizer"
}
},
"tokenizer": {
"document_number_tokenizer": {
"type": "pattern",
"pattern": "-0*([1-9][0-9]*)\/",
"group": 1
}
},
}
}
映射:
"number": {
"type": "keyword",
"copy_to": [
"_summary"
],
"fields": {
"sequenceNumber": {
"type": "text",
"analyzer": "document_number_analyzer"
}
}
}
编辑:
使用Integer子字段以对文档进行排序:错误:
022-05-18 11:33:32.5830 [ERROR] ESIndexerLogger Failed to commit bulk. Errors:
index returned 400 _index: adama_gen_ro_importdocument _type: _doc _id: 4c616067-4beb-4484-83cc-7eb9d36eb175 _version: 0 error: Type: mapper_parsing_exception Reason: "failed to parse field [number.sequenceNumber] of type [integer] in document with id '4c616067-4beb-4484-83cc-7eb9d36eb175'. Preview of field's value: 'BS-000011/2022'" CausedBy: "Type: number_format_exception Reason: "For input string: "BS-000011/2022"""
My task is to sort documents in ascending and descending order, but 'number' must remain of the keyword type. I read other posts on a similar topic, and tried to add an 'number' of type integer, but I didn't succeed and the index crashes. I am attaching the current configuration in the esMapping.js file.
Is there a way to fix this esMapping.js file so that ascending and descending sorting works?
"settings": {
"analysis": {
"analyzer": {
"document_number_analyzer": {
"type": "custom",
"tokenizer": "document_number_tokenizer"
}
},
"tokenizer": {
"document_number_tokenizer": {
"type": "pattern",
"pattern": "-0*([1-9][0-9]*)\/",
"group": 1
}
},
}
}
Mapping:
"number": {
"type": "keyword",
"copy_to": [
"_summary"
],
"fields": {
"sequenceNumber": {
"type": "text",
"analyzer": "document_number_analyzer"
}
}
}
EDIT:
Error after using integer sub-field to sort documents:
022-05-18 11:33:32.5830 [ERROR] ESIndexerLogger Failed to commit bulk. Errors:
index returned 400 _index: adama_gen_ro_importdocument _type: _doc _id: 4c616067-4beb-4484-83cc-7eb9d36eb175 _version: 0 error: Type: mapper_parsing_exception Reason: "failed to parse field [number.sequenceNumber] of type [integer] in document with id '4c616067-4beb-4484-83cc-7eb9d36eb175'. Preview of field's value: 'BS-000011/2022'" CausedBy: "Type: number_format_exception Reason: "For input string: "BS-000011/2022"""
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的映射需要这样:
然后您可以通过
number.SequenceNumber
进行排序。Your mapping needs to be like this:
And then you can simply sort by
number.sequenceNumber