有一个对话列表,每个对话都有一个消息列表。每条消息都有不同的字段和action
场地。我们需要考虑到在对话的第一条消息中使用了动作A
,在几条消息之后有使用的动作A.1
过了一会儿A.1.1
等等(有一个聊天机器人意图列表)。
对对话的消息操作进行分组将类似于:A > A > A > A.1 > A > A.1 > A.1.1 ...
Problem:
我需要使用 ElasticSearch 创建一个报告,该报告将返回actions group
每一次谈话;接下来,我需要将相似的分组actions groups
添加计数;最终会导致Map<actionsGroup, count>
as 'A > A.1 > A > A.1 > A.1.1', 3
.
构建actions group
我需要消除每组重复项;代替A > A > A > A.1 > A > A.1 > A.1.1
我需要有A > A.1 > A > A.1 > A.1.1
.
我开始做的步骤:
{
"collapse":{
"field":"context.conversationId",
"inner_hits":{
"name":"logs",
"size": 10000,
"sort":[
{
"@timestamp":"asc"
}
]
}
},
"aggs":{
},
}
接下来我需要什么:
- 我需要将崩溃的结果映射到单个结果中,例如
A > A.1 > A > A.1 > A.1.1
。我在案例中看到过这一点aggr
可以使用scripts https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-scripted-metric-aggregation.html根据结果,可以创建一个像我需要的操作列表,但是aggr
正在对所有消息进行操作,而不仅仅是对我崩溃的分组消息进行操作。是否可以使用aggr
内部崩溃或类似的解决方案?
- 我需要对结果值进行分组(
A > A.1 > A > A.1 > A.1.1
)从所有崩溃中添加一个计数并得到Map<actionsGroup, count>
.
Or:
- 对对话消息进行分组
conversationId
现场使用aggr
(我不知道我该怎么做)
- 使用脚本迭代所有值并创建
actions group
对于每一次对话。 (不确定这是否可能)
- 使用另一个
aggr
对所有值并对重复项进行分组,返回Map<actionsGroup, count>
.
映射:
"mappings":{
"properties":{
"@timestamp":{
"type":"date",
"format": "epoch_millis"
}
"context":{
"properties":{
"action":{
"type":"keyword"
},
"conversationId":{
"type":"keyword"
}
}
}
}
}
对话的样本文件:
Conversation 1.
{
"@timestamp": 1579632745000,
"context": {
"action": "A",
"conversationId": "conv_id1",
}
},
{
"@timestamp": 1579632745001,
"context": {
"action": "A.1",
"conversationId": "conv_id1",
}
},
{
"@timestamp": 1579632745002,
"context": {
"action": "A.1.1",
"conversationId": "conv_id1",
}
}
Conversation 2.
{
"@timestamp": 1579632745000,
"context": {
"action": "A",
"conversationId": "conv_id2",
}
},
{
"@timestamp": 1579632745001,
"context": {
"action": "A.1",
"conversationId": "conv_id2",
}
},
{
"@timestamp": 1579632745002,
"context": {
"action": "A.1.1",
"conversationId": "conv_id2",
}
}
Conversation 3.
{
"@timestamp": 1579632745000,
"context": {
"action": "B",
"conversationId": "conv_id3",
}
},
{
"@timestamp": 1579632745001,
"context": {
"action": "B.1",
"conversationId": "conv_id3",
}
}
预期结果:
{
"A -> A.1 -> A.1.1": 2,
"B -> B.1": 1
}
Something similar, having this or any other format.