【问题标题】:Getting list from Neo4j query从 Neo4j 查询中获取列表
【发布时间】:2016-04-04 11:26:47
【问题描述】:

我想创建一个节点子节点的 json。我正在使用此命令来获取特定节点的所有子节点:

match(t:TAG)<-[children:CHILD_OF]-(subtag:TAG) where t.name="brand" 
return t.eid as parent, collect(subtag.eid) as child

我得到这样的结果:

6aada019f7312fb1    [967b5461b2ff7c0b, a81e1772e4f9f7ef, 3dfbbd025548c0972a372a88e7de626af, 2009a1e160299c775d2ff15786ce33208, 2342ee1b2d940ef949442445eff52081c, 0b0f878f-5061-48e9-90db-8c64aa9f8982, 81692c4c-8acb-4aea-b985-ae493a1b9b67, e21c063c-7432-4094-85ac-16bf02f92a8e, 6fc485a0-5a05-49d0-a061-091077a95af7]

我现在想访问 java 中的孩子列表。

 String query = "match(t:TAG)<-[children:CHILD_OF]-(subtag:TAG) where t.name=\"brand\" return t.name as parent, subtag.name as child";
        Iterable<Map<String, Object>> itr = Neo4j.queryLagData(query, null);
 for(Map m : itr){
            String parent = (String)m.get("parent");
            String children = (String)m.get("child");

        }

我现在应该拆分孩子们的字符串吗?或者有没有一种方法可以直接给我一个孩子的列表,或者有一种方法可以直接给我一个json的孩子?

【问题讨论】:

    标签: java neo4j cypher


    【解决方案1】:

    。您的“子”字段应该是一个字符串列表。 .您应该为标签名称使用参数,例如 {name} .并且可以结合迭代和查询

    String query = "match(t:TAG)<-[children:CHILD_OF]-(subtag:TAG) where t.name={name} "+
                   "return t.name as parent, collect(subtag.name) as children";
    for(Map row : Neo4j.queryLagData(query, singletonMap("name","brand"))) {
        String parent = (String)row.get("parent");
        List<String> children = (List<String>)row.get("children");
    }
    

    【讨论】:

    • neo4j浏览器中如何传递参数?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 1970-01-01
    • 2017-06-05
    • 2013-08-20
    • 1970-01-01
    • 2016-12-12
    相关资源
    最近更新 更多