我是弹性搜索和解决方案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
的所有工作流时,你可以使用下面的查询来获取基于它们的start_time
的排序
{
"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
]
}
]