I am new to elasticsearch and working on POC of a solution. I have a use-case wherein i want to keep track of state changes of a ticket. The ticket id is the unique identifier for the data. I want to save the status changes, the time when status is changes and the comments on the ticket.
What is the best way to implement this?
I am saving my ticket data in an index with mapping defined as below:
"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" }
}
}
CodePudding user response:
Its difficult to visualise the problem and explain the solution without data, hence I created below data to explain it better:
Index Sample data
// 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"
}
After that when you want to get all the workflow of same ticket
jira-001
in my example, you can use below query to fetch that sort based on their start_time
{
"size": 10,
"query": {
"term": {
"ticket_id": "jira-001"
}
},
"sort": [
{
"start_time": "asc"
}
]
}
This will give below result, Hope this helps and is according to your use-case.
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
]
}
]