Kibana仪表板 - 来自2个具有相同映射的索引的源数据

时间:2015-07-16 09:48:27

标签: kibana querydsl kibana-4

我正在尝试设置Kibana仪表板。 在Elasticsearch中,只有一种类型的文档 我们有两个具有相同映射的索引:

指数product_1product_2

"_index": "product_1",
"_type": "product",
"_id": "3da33451d10f095c4b8cd485133dc23639244538",
"_score": 1,
"_source": {
    ...
    source": { "brand": "","category": "","store": "Store1"}
    ...
}

"_index": "product_1",
"_type": "product",
"_id": "3da33451d10f095c4b8cd485133dc23639244538",
"_score": 1,
"_source": {
    ...
    source": { "brand": "","category": "","store": "Store2"}
    ...
}
...

我们设法创建了可视化 我们需要计算每个字段store的产品(文档)总数:

Top 0 source.store    Count
Store1                52,517
Store2                31,517
Store3                12,838
...

所以,问题是:我们如何在这里添加第二个索引的数据,以获得这样的结果:

Top 0 source.store    Count (product_1)    Count (product_2)
Store1                52,517               42,517
Store2                31,517               56,517
Store3                12,838               13,890
...

非常感谢。

PS:我们设法收集了2个指数的数据:
["product_1","product_2"]
所以kibana来源数据,好像它是一个索引,我们得到了错误的结果:

Top 0 source.store    Count (product_1+product_2)
Store1                102,517
Store2                62,517
Store3                24,838
...

1 个答案:

答案 0 :(得分:0)

我不完全确定你所尝试的是否可能。来自the elastic search index documentation

The easiest and most familiar layout clones what you would expect from a relational database. 
You can (very roughly) think of an index like a database.

MySQL => Databases => Tables => Columns/Rows
Elasticsearch => Indices => Types => Documents with Properties

正如我在这里所理解的那样,你试图在一个查询中从两个数据库(索引)中获取数据,据我所知,这是不可能的 - 至少按照你想要的方式,即根据到指数。

现在你可能(应该)有一个问题,如果这完全不可能,你是如何得到以下结果的?

Top 0 source.store    Count (product_1+product_2)
Store1                102,517
Store2                62,517
Store3                24,838

这就是Kibana魔法的所在。您可以使用通配符创建索引模式。这将查询卡内的每个索引。例如,创建logstash- *将查询所有logstash- [date]索引并给出您看到的合并结果。在您的情况下,可以通过将索引模式创建为 product _ * 来实现。但我认为你不能得到索引方面的各种结果(我想,这正是你正在寻找的)。

相关问题