【发布时间】:2015-11-14 10:36:09
【问题描述】:
有没有办法让 Elasticsearch 在分组时考虑序列间隙?
假设以下数据被批量导入到 Elasticsearch:
{ "index": { "_index": "test", "_type": "groupingTest", "_id": "1" } }
{ "sequence": 1, "type": "A" }
{ "index": { "_index": "test", "_type": "groupingTest", "_id": "2" } }
{ "sequence": 2, "type": "A" }
{ "index": { "_index": "test", "_type": "groupingTest", "_id": "3" } }
{ "sequence": 3, "type": "B" }
{ "index": { "_index": "test", "_type": "groupingTest", "_id": "4" } }
{ "sequence": 4, "type": "A" }
{ "index": { "_index": "test", "_type": "groupingTest", "_id": "5" } }
{ "sequence": 5, "type": "A" }
有没有办法以某种方式查询这些数据
- 序列号为 1 和 2 的文档进入一个输出组,
- 序列号为 3 的文档转到另一个文档,并且
- 序列号为 4 和 5 的文档进入第三组?
...考虑到 A 类序列被 B 类项目(或任何其他非 A 类项目)打断的事实?
我希望结果桶看起来像这样(sequence_group 的名称和值可能不同 - 只是试图说明逻辑):
"buckets": [
{
"key": "a",
"sequence_group": 1,
"doc_count": 2
},
{
"key": "b",
"sequence_group": 3,
"doc_count": 1
},
{
"key": "a",
"sequence_group": 4,
"doc_count": 2
}
]
https://www.simple-talk.com/sql/t-sql-programming/the-sql-of-gaps-and-islands-in-sequences/ 上有一个很好的问题描述和一些 SQL 解决方案方法。我想知道是否还有可用的弹性搜索解决方案。
【问题讨论】:
标签: elasticsearch gaps-and-islands