gpt4 book ai didi

elasticsearch - 如何在 Elasticsearch 中针对唯一 ID 保存状态或状态转换

转载 作者:行者123 更新时间:2023-12-05 05:33:59 28 4
gpt4 key购买 nike

我是 elasticsearch 的新手,正在研究解决方案的 POC。我有一个用例,其中我想跟踪票证的状态变化。工单 ID 是数据的唯一标识符。我想保存状态变化,状态变化的时间和工单上的评论。

实现它的最佳方法是什么?

我将我的工单数据保存在一个索引中,其映射定义如下:

"mappings": {
"properties":
{
"ticket_id": { "type": "keyword" },
"Problem Description": { "type": "text" },
"start_time" :{"type": "date","format":"yyyy-MM-dd HH:mm:ss"},
"end_time" :{"type": "date","format":"yyyy-MM-dd HH:mm:ss"},
"workflow_status":{"type": "text" }
}
}

最佳答案

如果没有数据,很难将问题可视化并解释解决方案,因此我创建了以下数据来更好地解释它:

索引示例数据

// below document doesn't marks the status to `done` hence just the `start_time` change with Description.

{
"ticket_id" : "jira-001",
"Problem_Description" : "this is first jira-001",
"start_time" : "2022-09-14 05:30:00",
"workflow_status" : "backlog"
}

// below document doesn't marks the status to `done` hence just the `start_time` change with Description.


{
"ticket_id" : "jira-001",
"Problem_Description" : "working on jira-001",
"start_time" : "2022-09-14 07:30:00",
"workflow_status" : "in-progress"
}

// below document marks the status to `done` hence `end_time`
{
"ticket_id" : "jira-001",
"Problem_Description" : "completed jira-001",
"start_time" : "2022-09-15 01:30:00",
"end_time" : "2022-09-15 04:30:00",
"workflow_status" : "done"
}

在我的示例中,当您想要获取同一 ticket jira-001 的所有工作流时,您可以使用下面的查询来根据它们的 开始时间

{
"size": 10,
"query": {
"term": {
"ticket_id": "jira-001"
}
},
"sort": [
{
"start_time": "asc"
}
]
}

这将给出以下结果,希望这对您有所帮助并且符合您的用例。

hits": [
{
"_index": "73706581",
"_id": "1",
"_score": null,
"_source": {
"ticket_id": "jira-001",
"Problem_Description": "this is first jira-001",
"start_time": "2022-09-14 05:30:00",
"workflow_status": "backlog"
},
"sort": [
1663133400000
]
},
{
"_index": "73706581",
"_id": "2",
"_score": null,
"_source": {
"ticket_id": "jira-001",
"Problem_Description": "working on jira-001",
"start_time": "2022-09-14 07:30:00",
"workflow_status": "in-progress"
},
"sort": [
1663140600000
]
},
{
"_index": "73706581",
"_id": "3",
"_score": null,
"_source": {
"ticket_id": "jira-001",
"Problem_Description": "completed jira-001",
"start_time": "2022-09-15 01:30:00",
"end_time": "2022-09-15 04:30:00",
"workflow_status": "done"
},
"sort": [
1663205400000
]
}
]

关于elasticsearch - 如何在 Elasticsearch 中针对唯一 ID 保存状态或状态转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73706581/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com