用于排序索引和通配符查询的 ElasticSearch 字段

ElasticSearch field for sort index and wildcard query

我有一个 ID 字段,它是一个 UUID,我想将其用作唯一排序(因为 created_at 不是唯一的)和通配符查询。 例如,搜索 b85f9fdd 将得到 ID 为 b85f9fdd-5557-4f70-bbd7-9a23b0485235 的文档 我已尝试创建此索引:

{
    "settings": {
        "index": {
            "sort.field": [ "created_at", "id" ],
            "sort.order": [ "desc", "desc" ]
        }
    },
    "mappings": {
        "properties": {
            "id": { "type": "wildcard", "fields": { "raw": { "type": "keyword" }}},
            "current_status": { "type": "keyword" },
            "version_rev":    { "type": "keyword" },
            "tracking_id":     { "type": "wildcard" },
            "invoice_number":  { "type": "keyword" },
            "created_at":     { "type": "date" }
            }
        }
    }
}

但是我得到了回复:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "invalid index sort field:[id]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "invalid index sort field:[id]"
    },
    "status": 400
}

您需要按 id.raw 排序:

"settings": {
    "index": {
        "sort.field": [ "created_at", "id.raw" ],
        "sort.order": [ "desc", "desc" ]
    }
},