apoc.graph.filterProperties

函数 Apoc 扩展

apoc.graph.filterProperties(anyEntityObject, nodePropertiesToRemove, relPropertiesToRemove)

Aggregation function which returns an object {node: [virtual nodes], relationships: [virtual relationships]} without the properties defined in nodePropertiesToRemove and relPropertiesToRemove

签名

apoc.graph.filterProperties(value :: ANY?, nodePropertiesToRemove :: MAP?, relPropertiesToRemove :: MAP?) :: ANY?

nodePropertiesToRemoverelPropertiesToRemove 参数是映射(map),其键(key)为标签/关系类型,值为要从虚拟实体中移除的属性列表。对于两者,键也可以是 _all,这意味着每个标签/关系类型的属性都会被过滤。

用法示例

假设有以下数据集

CREATE (:Person {name: "foo", plotEmbedding: "11"})-[:REL {idRel: 1, posterEmbedding: "33"}]->(:Movie {name: "bar", plotEmbedding: "22"}),
                 (:Person {name: "baz", plotEmbedding: "33"})-[:REL {idRel: 1, posterEmbedding: "66"}]->(:Movie {name: "ajeje", plotEmbedding: "44"})

我们可以执行

MATCH path=(:Person)-[:REL]->(:Movie)
WITH apoc.graph.filterProperties(path, {Movie: ['posterEmbedding'], Person: ['posterEmbedding', 'plotEmbedding', 'plot', 'bio']}) as graph
RETURN graph.nodes AS nodes, graph.relationships AS relationships
表 1. 结果
节点 relationships

[(:Person {name: "1"}), (:Movie {name: "bar"}), (:Movie {title: "1",tmdbId: "ajeje"}), (:Person {name: "baz"}), (:Person {name: "uno"}), (:Movie {name: "ajeje"}), (:Movie {title: "1",tmdbId: "due"}), (:Movie {title: "1",tmdbId: "ajeje"}), (:Person {name: "1"}), (:Movie {title: "1",tmdbId: "ajeje"}), (:Person {name: "foo"}), (:Person {name: "1"})]

[[:REL], [:REL {idRel: 1}], [:REL {idRel: 1}], [:REL], [:REL], [:REL]]│

MATCH path=(:Person)-[:REL]->(:Movie)
WITH apoc.graph.filterProperties(path, {_all: ['plotEmbedding', 'posterEmbedding', 'plot', 'bio']}) as graph
RETURN graph.nodes AS nodes, graph.relationships AS relationships

结果与上述相同。

© . This site is unofficial and not affiliated with Neo4j, Inc.