有一些cypher查询和数字索引的问题
@Indexed(unique = true, numeric = false)
private Long accountId;
返回:
neo4j-sh (0)$ start n=node:Principal(accountId = '1') return n;
+---------------------------------------------------------------------------------------------+
| n |
+---------------------------------------------------------------------------------------------+
| Node[41722]{__type__:"example.package.Principal",accountId:1,name:"Simple User"} |
+---------------------------------------------------------------------------------------------+
1 row
但是
@Indexed(unique = true, numeric = true)
private Long accountId;
返回:
neo4j-sh (0)$ start n=node:Principal(accountId = '1') return n;
+---+
| n |
+---+
+---+
0 row
neo4j 1.9.2
spring-data-neo4j 2.3.0.RC1
如果我理解正确,这可能会被discussion强烈抨击,但它已经很老了?
更新
如果我使用
@Indexed(unique = true, numeric = false)
另一个有趣的事情发生了。检查是否存在关系(它实际存在于db中):
count(r)等于0 - 不正确:
Long accountId = 1L;
Map<String, Object> result = template.query(
"START child=node:Principal(accountId='{childId}') " +
"MATCH child-[r:IS_MEMBER_OF]->parent " +
"RETURN count(r)", MapUtil.map("childId", accountId)).singleOrNull();
count(r)等于1 - 正确:
Long accountId = 1L;
Map<String, Object> result = template.query(
"START child=node:Principal(accountId='1') " +
"MATCH child-[r:IS_MEMBER_OF]->parent " +
"RETURN count(r)",null).singleOrNull();
答案 0 :(得分:1)
数字索引查找不能使用带有文字值的cypher,lucene解析器不会创建正确的内部查询。同样使用参数,传递给索引的正常原始值在neo4j lucene实现中被视为字符串,因为查询无法知道数据是以数字方式索引还是以字符串形式索引。
// this won't work, you have to remove the single quotes around '{childId}'
"START child=node:Principal(accountId='{childId}') " +
"MATCH child-[r:IS_MEMBER_OF]->parent " +
"RETURN count(r)", MapUtil.map("childId", accountId)).singleOrNull();
使用cypher进行数字查询的唯一方法是将ValueContext.numeric(1)
值作为java-parameter-map中的参数传递给嵌入式数据库。