使用密码按属性匹配ID数组



我正在使用Neo4J Desktop测试我正在尝试编写的密码查询。

数据库包含许多对象,例如:

{
"identity": 44494216,
"labels": [
"WikiEntity"
],
"properties": {
"date_added": "2022-01-11T00:00:00",
"indexed_text": "Johnny Dyer",
"name": "John Dyer (rugby union)",
"wikipediaID": "https://en.wikipedia.org/wiki/John_Dyer_(rugby_union)",
"type": "PERSON",
"parent_bin": "parent_0_230_303",
"uuid": "c378ff81-dea3-48e3-8411-4fb1cd085438"
}
}

{
"identity": 162983523,
"labels": [
"Topic"
],
"properties": {
"topicID": "progressive politics-t",
"topicAlternateID": "XXX8383291769194810424",
"name": "Progressive Politics",
"parent_bin": "parent_0_217_230",
"uuid": "f8358b4f-e656-4290-ab26-2270c1d76088",
"slug": "progressive-politics"
}
}

我希望能够返回从我提供的ID数组中匹配的对象的uuid,并且我还希望仅返回具有WikiEntityTopicKeywordlabel的匹配。

理想情况下,我希望能够返回一个看起来像这样的对象:

{
Keywords: [], // list of matching uuids 
Topics: [], // list of matching uuids 
Entities: [] // list of matching uuids 
}

您可以这样做,假设您在参数$yourUuids中提供uuid

MATCH (n)
WHERE n.uuid IN $yourUuids
AND (n:Topic OR n:Keyword OR n:WikiEntity)
WITH COLLECT(n) AS ns
RETURN { 
Keywords: [n IN ns WHERE n:Keyword | n.uuid],
Topics: [n IN ns WHERE n:Topic | n.uuid],
Entities: [n IN ns WHERE n:WikiEntity | n.uuid]
}

对已接受的答案进行轻微修改才是真正对我有效的(我的问题不清楚我是否会提供NodeId来匹配(:

MATCH (n)
WHERE ID(n) IN [44494216, 72870481]
AND (n:Topic OR n:Keyword OR n:WikiEntity)
WITH COLLECT(n) AS ns
RETURN { 
Keywords: [n IN ns WHERE n:Keyword | n.uuid],
Topics: [n IN ns WHERE n:Topic | n.uuid],
Entities: [n IN ns WHERE n:WikiEntity | n.uuid]
}

最新更新