neo4j find all nodes with matching properties

后端 未结 7 2048
走了就别回头了
走了就别回头了 2020-12-30 04:15

I have a relatively large set of nodes, and I want to find all pairs of nodes that have matching property values, but I don\'t know or care in advance what the property valu

7条回答
  •  遥遥无期
    2020-12-30 04:51

    The best/easiest option is to do something like a local Map. If you did something like this, you could create code like this:

    GlobalGraphOperations ggo = GlobalGraphOperations.at(db);
    Map duplicateMap = new HashMap();
    
    for (Node node : ggo.getAllNodes()) {
        Object propertyValue = node.getProperty("property");
        Node existingNode = duplicateMap.get(propertyValue);
        if (existingNode == null) {
            duplicateMap.put(propertyValue, node);
        } else {
            System.out.println("Duplicate Node. First Node: " + existingNode + ", Second Node: " + node);
        }
    }
    

    This would print out a list. If you needed to do more, like remove these nodes, you could do something in the else.

    Do you know the property name? Will this be multiple properties, or just duplicates of a single name/value pair? If you are doing multiple properties, just create a map for each property you have.

提交回复
热议问题