我有这样的节点,我需要对其应用过滤器
{
"value": "ma",
"object_field_id": 2293
}
{
"value": 2,
"object_field_id": 2294
}
MATCH (:UserData {user_id:19})-[:CARD]-(c:Card)-[:FIELD_GROUP]-()-[:FIELD]-(fi:Field)
WHERE fi.object_field_id IN [23,24]
AND (fi.value=~('(?iu).*149.*')
AND fi.value=~('(?iu).*gb.*'))
RETURN c
但不适用于AND
我的错误在哪里?
答案 0 :(得分:0)
我清理了Cypher查询以创建数据库,希望我没有犯任何错误。您会注意到,我删除了所有WITH count(*) as dummy
,因为它们不是必需的,只会导致错误。对于同时具有MATCH
和CREATE
的语句,它们需要一个WITH
。我对类似的语句进行了重新排序和分组,以便它们都可以在一条语句中完成,例如以;
结尾。
CREATE (:UserData {user_id: 19});
MATCH (n:UserData {user_id: 19})
WITH n
CREATE (n)-[:CARD]->(:Card {name: "card"});
CREATE (:FieldUserGroup {data_id: 1290})
CREATE (:FieldUserGroup {data_id: 1280})
CREATE (:FieldUserGroup {data_id: 1270});
MATCH (f1:FieldUserGroup {data_id: 1290}),
(f2:FieldUserGroup {data_id: 1280}),
(f3:FieldUserGroup {data_id: 1270}),
(c1:Card {name: "card"})
WITH f1,f2,f3,c1
CREATE (c1)-[:FIELD_GROUP]->(f1)
CREATE (c1)-[:FIELD_GROUP]->(f2)
CREATE (c1)-[:FIELD_GROUP]->(f3);
CREATE (:Field {value: "jerry", object_field_id: 11})
CREATE (:Field {value: 2, object_field_id: 12})
CREATE (:Field {value: "tom", object_field_id: 13})
CREATE (:Field {value: "jack", object_field_id: 14})
CREATE (:Field {value: 1234, object_field_id: 15})
CREATE (:Field {value: "robin", object_field_id: 16})
CREATE (:Field {value: "zazaza", object_field_id: 17})
CREATE (:Field {value: 6578970, object_field_id: 18})
CREATE (:Field {value: "hamlet", object_field_id: 19});
MATCH (f1:FieldUserGroup {data_id: 1290}),
(c11:Field {value: "jerry"}),
(c12:Field {value: 2}),
(c13:Field {value: "tom"}),
(f2:FieldUserGroup {data_id: 1280}),
(c21:Field {value: "jack"}),
(c22:Field {value: 1234}),
(c23:Field {value: "robin"}),
(f3:FieldUserGroup {data_id: 1270}),
(c31:Field {value: "zazaza"}),
(c32:Field {value: 6578970}),
(c33:Field {value: "hamlet"})
WITH f1,f2,f3,c11,c12,c13,c21,c22,c23,c31,c32,c33
CREATE (f1)-[:FIELD]->(c11)
CREATE (f1)-[:FIELD]->(c12)
CREATE (f1)-[:FIELD]->(c13)
CREATE (f2)-[:FIELD]->(c21)
CREATE (f2)-[:FIELD]->(c22)
CREATE (f2)-[:FIELD]->(c23)
CREATE (f3)-[:FIELD]->(c31)
CREATE (f3)-[:FIELD]->(c32)
CREATE (f3)-[:FIELD]->(c33);
MATCH (n:UserData {user_id: 19})
WITH n
CREATE (n)-[:CARD]->(:Card {name: "card2"});
CREATE (:FieldUserGroup {data_id: 1240})
CREATE (:FieldUserGroup {data_id: 1250})
CREATE (:FieldUserGroup {data_id: 1260});
MATCH (f1:FieldUserGroup {data_id: 1240}),
(f2:FieldUserGroup {data_id: 1250}),
(f3:FieldUserGroup {data_id: 1260}),
(c1:Card {name: "card2"})
WITH f1,f2,f3,c1
CREATE (c1)-[:FIELD_GROUP]->(f1)
CREATE (c1)-[:FIELD_GROUP]->(f2)
CREATE (c1)-[:FIELD_GROUP]->(f3);
CREATE (:Field {value: "some value", object_field_id: 20})
CREATE (:Field {value: "more value", object_field_id: 21})
CREATE (:Field {value: "this is insane!", object_field_id: 22})
CREATE (:Field {value: 14948576, object_field_id: 23})
CREATE (:Field {value: "GB", object_field_id: 24})
CREATE (:Field {value: 1, object_field_id: 25})
CREATE (:Field {value: 2, object_field_id: 26})
CREATE (:Field {value: "Marky", object_field_id: 27})
CREATE (:Field {value: "Tom Born", object_field_id: 28});
MATCH (f1:FieldUserGroup {data_id: 1240}),
(c11:Field {value: 2, object_field_id: 26}),
(c12:Field {value: "Marky"}),
(c13:Field {value: "Tom Born"}),
(f2:FieldUserGroup {data_id: 1250}),
(c21:Field {value: 14948576}),
(c22:Field {value: "GB"}),
(c23:Field {value: 1}),
(f3:FieldUserGroup {data_id: 1260}),
(c31:Field {value: "some value"}),
(c32:Field {value: "more value"}),
(c33:Field {value: "this is insane!"})
WITH f1,f2,f3,c11,c12,c13,c21,c22,c23,c31,c32,c33
CREATE (f1)-[:FIELD]->(c11)
CREATE (f1)-[:FIELD]->(c12)
CREATE (f1)-[:FIELD]->(c13)
CREATE (f2)-[:FIELD]->(c21)
CREATE (f2)-[:FIELD]->(c22)
CREATE (f2)-[:FIELD]->(c23)
CREATE (f3)-[:FIELD]->(c31)
CREATE (f3)-[:FIELD]->(c32)
CREATE (f3)-[:FIELD]->(c33);
原始查询
MATCH (:UserData {user_id:19})-[:CARD]-(c:Card)-[:FIELD_GROUP]-()-[:FIELD]-(fi:Field)
WHERE fi.object_field_id IN [23,24]
AND (fi.value=~('(?iu).*149.*')
AND fi.value=~('(?iu).*gb.*'))
RETURN c
在不返回任何记录时工作正常。这是因为没有匹配查询这一部分的节点
MATCH (fi:Field)
WHERE fi.value=~('(?iu).*149.*')
RETURN fi;
也不会返回任何记录。 AND
子句可以正常工作。
答案 1 :(得分:0)
这里是用于建立关系和节点的查询数据:
CREATE (a:UserData {user_id: 19})-[r:CARD]->(b:Card {name: "card"})
WITH count(*) as dummy
CREATE (a:FieldUserGroup {data_id: 1290})
WITH count(*) as dummy
CREATE (a:FieldUserGroup {data_id: 1280})
WITH count(*) as dummy
CREATE (a:FieldUserGroup {data_id: 1270})
WITH count(*) as dummy
MATCH (u:FieldUserGroup), (c:Card) CREATE (c)-[:FIELD_GROUP]->(u)
WITH count(*) as dummy
create (f:Field {value: "jerry", object_field_id: 11})
WITH count(*) as dummy
create (f:Field {value: 2, object_field_id: 12})
WITH count(*) as dummy
create (f:Field {value: "tom", object_field_id: 13})
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1290}), (f2:Field) CREATE (f)-[:FIELD]->(f2)
WITH count(*) as dummy
CREATE (c:Field {value: "jack", object_field_id: 14})
WITH count(*) as dummy
CREATE (c:Field {value: 1234, object_field_id: 15})
WITH count(*) as dummy
CREATE (c:Field {value: "robin", object_field_id: 16})
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1280}), (c:Field {value: "jack", object_field_id: 14}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1280}), (c:Field {value: 1234, object_field_id: 15}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1280}), (c:Field {value: "robin", object_field_id: 16}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
CREATE (c:Field {value: "zazaza", object_field_id: 17})
WITH count(*) as dummy
CREATE (c:Field {value: 6578970, object_field_id: 18})
WITH count(*) as dummy
CREATE (c:Field {value: "hamlet", object_field_id: 19})
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1270}), (c:Field {value: "zazaza", object_field_id: 17}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1270}), (c:Field {value: 6578970, object_field_id: 18}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1270}), (c:Field {value: "hamlet", object_field_id: 19}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
CREATE (r:card {name: "card2"})
WITH count(*) as dummy
MATCH (r:card {name: "card2"}), (a:UserData {user_id: 19}) CREATE (a)-[:CARD]->(r)
WITH count(*) as dummy
CREATE (a:FieldUserGroup {data_id: 1260})
WITH count(*) as dummy
CREATE (a:FieldUserGroup {data_id: 1250})
WITH count(*) as dummy
CREATE (a:FieldUserGroup {data_id: 1240})
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1260}), (r:card {name: "card2"}) CREATE (r)-[:CARD]->(f)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1250}), (r:card {name: "card2"}) CREATE (r)-[:CARD]->(f)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1240}), (r:card {name: "card2"}) CREATE (r)-[:CARD]->(f)
WITH count(*) as dummy
CREATE (c:Field {value: "some value", object_field_id: 20})
WITH count(*) as dummy
CREATE (c:Field {value: "more value", object_field_id: 21})
WITH count(*) as dummy
CREATE (c:Field {value: "this is insane!", object_field_id: 22})
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1260}), (c:Field {object_field_id: 20}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1260}), (c:Field {object_field_id: 21}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1260}), (c:Field {object_field_id: 22}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
CREATE (c:Field {value: 14948576, object_field_id: 23})
WITH count(*) as dummy
CREATE (c:Field {value: "GB", object_field_id: 24})
WITH count(*) as dummy
CREATE (c:Field {value: 1, object_field_id: 25})
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1250}), (c:Field {object_field_id: 23}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1250}), (c:Field {object_field_id: 24}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1250}), (c:Field {object_field_id: 25}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
CREATE (c:Field {value: 2, object_field_id: 26})
WITH count(*) as dummy
CREATE (c:Field {value: "Marky", object_field_id: 27})
WITH count(*) as dummy
CREATE (c:Field {value: "Tom Born", object_field_id: 28})
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1240}), (c:Field {object_field_id: 26}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1240}), (c:Field {object_field_id: 27}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
MATCH (f:FieldUserGroup {data_id: 1240}), (c:Field {object_field_id: 28}) CREATE (f)-[:FIELD]->(c)
WITH count(*) as dummy
答案 2 :(得分:0)
UPD:
这是有效的查询,但只能在FieldUserGroup的一侧
MATCH (c:Card)-[:FIELD_GROUP]-()-[:FIELD]-(fi:Field) where (any(prop in keys(fi) where fi[prop] =~ '(?iu).*tom.*'))
return c