在 Cypher,Neo4j 中使用 WITH 过滤具有多个条件的列表

Filter a list with multiple conditions using WITH in Cypher,Neo4j

我是 Neo4j 的新手。我有点难以将 JSON 文件加载到 Neo4j 数据库中。 我有许多交易的标签列表。每个交易标签可以有一个或两个标签:第三方和类别。

这是一个例子JSON。

{
    "tags": [
        [
            {
                "thirdParty": "Supermarkets"
            },
            {
                "category": "Groceries"
            }
        ],
        [
            {
                "category": "Rent"
            }
        ],
        [
            {
                "thirdParty": "Education"
            },
            {
                "category": "Education"
            }
        ]
        .....
    ]
}

我只想查找同时具有类别和第三方的对象(有些对象只有一个标签)。

这是我的代码,列表只是我想要的类别列表。

CALL apoc.load.json("file:///full.json")
YIELD value
with ['Gambling','Subscription TV','Telecommunications'] as list
UNWIND value.tags as tags
WITH [tag in tags where tag.category IN list AND tag.thirdParty IS NOT NULL] AS temp
RETURN temp

奇怪的是这总是 return 我的列表为空。但是只有一个条件才会起作用,比如只在列表中找到对象或者只有第三方不为空。 但是将这两个条件组合在一起,它总是 return 一个空列表。

有人知道如何解决这个问题吗?

谢谢

您的 UNWIND 似乎 return 地图列表,而不是地图。但好处是有了apoc,你可以很容易地转换它。

这个有效:

WITH [
        [
            {
                thirdParty: "Supermarkets"
            },
            {
                category: "Groceries"
            }
        ],
        [
            {
                category: "Rent"
            }
        ],
        [
            {
                thirdParty: "Education"
            },
            {
                category: "Education"
            }
        ]
    ]
AS tagsList

WITH tagsList, ['Groceries','Subscription TV','Telecommunications'] as list
UNWIND tagsList as tags
WITH list,
     apoc.map.fromPairs(
        REDUCE(arr=[],tag IN tags | 
               arr+[[keys(tag)[0],tag[keys(tag)[0]]]]
        )
     ) AS tagMap
WHERE tagMap.category IN list AND tagMap.thirdParty IS NOT NULL
RETURN tagMap

returns

{
  "thirdParty": "Supermarkets",
  "category": "Groceries"
}