父子关系可视化,模式匹配和全文搜索

时间:2017-03-11 02:10:29

标签: python elasticsearch neo4j kibana

我有一个如下数据集:

Parent  ID    Path      GrandParent  GrandParentID   Child  ModPath 
John    100   home\123  Matt         50              Ian      Ian\123
John    100   home\123  Matt         50              Andrew   Andrew\123
John    100   home\123  Matt         50              Danny    Danny\123

如何在Kibana / elasticsearch中最好地表示我的数据,以显示每个事件的父子结构?理想情况下,我想将上面的这个集合分类为单个事件,就像我在下面的Python Pandas中使用groupby一样。

Parent  ID    Path      GrandParent  GrandParentID   Child    ModPath 
John    100   home\123  Matt         50              Ian      Ian\123
                                                     Andrew   Andrew\123
                                                     Danny    Danny\123

如果kibana / elasticsearch不是最好的方法/工具集,那么您是否可以推荐任何其他可视化和引用的工具集/方法?

理想情况下,我希望能够搜索父母,子女或祖父母,并在视觉上或表格中显示关系的所有关系和属性。

Python是一个由于引用pandas而使用的标记。

2 个答案:

答案 0 :(得分:1)

Neo4j非常擅长模式匹配和关系可视化。 ElasticSearch在全文搜索方面更好,但是Neo4j应该能够通过一些小的改动来充分处理它。

以下是如何在Neo4j中对此进行建模和查询的示例,以及查询的表格和图形结果。您可以使用它来与其他答案以及您尝试的其他解决方案进行比较。

现在让我们将它们建模为:人员节点,它们之间有:CHILD关系。

你还没有暗示数据比这三代更进一步,所以现在让我们说数据库中的所有结构都遵循这种模式。

在Cypher中,让我们在示例图中创建节点:

create (matt:Person{name:'Matt', ID:50})
create (john:Person{name:'John', ID:100, path:'home/123'})
create (ian:Person{name:'Ian', path:'Ian/123'})
create (andrew:Person{name:'Andrew', path:'Andrew/123'})
create (danny:Person{name:'Danny', path:'Danny/123'})

create (matt)-[:CHILD]->(john)
create (john)-[:CHILD]->(ian)
create (john)-[:CHILD]->(andrew)
create (john)-[:CHILD]->(danny)

接下来让我们确保其名称的小写版本可以利用索引查找:

match (p:Person)
set p.lowerName = lower(p.name)

然后我们将在lowerName上添加索引,以便将来的任何匹配都很快:

create index on :Person(lowerName)

我们已准备好进行查询。

我们在这里使用了硬编码的小写lookup,但在实际版本中,您lookup为参数,并在其上运行lower()在比赛前把它变成小写。

with 'ian' as lookup
// find the grandparent root node
match (:Person{lowerName:lookup})<-[:CHILD*0..]-(grandparent)
where size ((grandparent)<-[:CHILD]-()) = 0
with grandparent
match p=(grandparent)-[:CHILD]->(parent)-[:CHILD]->(child)
return parent.name as Parent, parent.ID as ID, parent.path as Path,
       grandparent.name as GrandParent, grandparent.ID as GrandParentID, 
       collect(child {Child:child.name, ModPath:child.path}) as children, 
       collect(p) as path

无论您在查询中使用哪个名称,这都将有效。它将为每个祖父+父对和所有父母的子女返回一行。收集匹配的路径到孩子们确保尽管有投影,仍然可以获得结果的图形视图。

您当然可以以不同方式执行投影,具体取决于您要公开的数据,或者直接返回节点,其中包括所有属性。

这里是结果行和列(忽略路径列): enter image description here

这里是结果的图形视图: enter image description here

答案 1 :(得分:0)

弹性搜索具有内部功能,可根据需要将父级和子级包含在内。如果将此结果输入neo4j,您将具有预期的视觉效果

相关问题