启用关键字类型的数字的升序和降序排序(Elasticsearch)

Enable ascending and descending sorting of numbers that are of the keyword type (Elasticsearch)

我的任务是按升序和降序对文档进行排序,但'number'必须保留关键字类型。我阅读了关于类似主题的其他帖子,并尝试添加一个 'number' 类型的整数,但我没有成功,索引崩溃了。我在 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"
                }
            }
        }

编辑:

使用整数子字段对文档进行排序后出错:

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"""

你的映射需要像这样:

    "number": {
        "type": "keyword",
        "copy_to": [
            "_summary"
        ],
        "fields": {
            "sequenceNumber": {
                "type": "integer"
            }
        }
    }

然后您可以简单地按 number.sequenceNumber

排序