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

发布于 2025-01-26 09:23:09 字数 1536 浏览 1 评论 0原文

我的任务是按上升和下降顺序排序文档,但是“数字”必须保留在关键字类型中。我阅读了有关类似主题的其他帖子,并试图添加一个“数量”类型整数,但我没有成功,索引崩溃了。我正在将当前配置附加在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疏忽 2025-02-02 09:23:09

您的映射需要这样:

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

然后您可以通过number.SequenceNumber进行排序。

Your mapping needs to be like this:

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

And then you can simply sort by number.sequenceNumber

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文