Neo4j 中批量插入期间的数字索引
我正在将节点和关系批量插入到 Neo4j 图形数据库中。一切正常,包括多个属性 ([String] name, [int] id)
上的索引。但是,当我尝试按范围查询属性“id”上的索引时,它不返回任何结果。
这个问题,正如我从 非批量示例,是我无法像这样向 BatchInserterIndex
提供数字 ValueContext
:
Map<String, Object> properties = new HashMap<String, Object>(2);
properties.put("name", urs.getString(1));
// I can do this:
properties.put("id", urs.getInt(2));
// But not this (throws an "invalid type" exception):
// properties.put("id", new ValueContext( urs.getInt(2) ).indexNumeric());
long node_id = inserter.createNode(properties);
index.add(node_id, properties);
我没有找到任何 有关批量插入期间数字索引的文档。
查询代码如下:
IndexManager index = gdb.index();
Index<Node> people = index.forNodes("people");
IndexHits<Node> hits = people.query(
QueryContext.numericRange("id", min_id, max_id)
);
是否可以在批量插入操作中添加数字索引,以便我可以按范围查询值?
谢谢。
编辑
我做错的是我尝试将相同的属性映射传递给 createNode()
和 index.add()
。前者崩溃了,因为它不需要 ValueContext
并且不理解它。因此,请务必将不同的属性映射传递给这些方法,并在用于 index.add
的值中包含 ValueContext
-ed 数值:
Long value = 1L;
long node_id = inserter.createNode(
MapUtil.map("id", value, "other_prop", other_value));
index.add(node_id,
MapUtil.map("id", ValueContext.numeric( value ), "other_prop", other_value));
I'm using batch insertion of nodes and relationships into Neo4j graph database. Everything works, including the index on multiple properties ([String] name, [int] id)
. However, when I try to query the index on property "id" by range, it returns no results.
The problem, as I derived it from the non-batch example, is that I can't supply numeric ValueContext
to the BatchInserterIndex
like so:
Map<String, Object> properties = new HashMap<String, Object>(2);
properties.put("name", urs.getString(1));
// I can do this:
properties.put("id", urs.getInt(2));
// But not this (throws an "invalid type" exception):
// properties.put("id", new ValueContext( urs.getInt(2) ).indexNumeric());
long node_id = inserter.createNode(properties);
index.add(node_id, properties);
I haven't found any documentation regarding numeric indexing during batch insertion.
The query code is as follows:
IndexManager index = gdb.index();
Index<Node> people = index.forNodes("people");
IndexHits<Node> hits = people.query(
QueryContext.numericRange("id", min_id, max_id)
);
Is it at all possible to add numeric index in a batch insertion operation, so that I can then query values by range?
Thanks.
Edit
What I was doing wrong is I tried to pass the same property map to createNode()
and index.add()
. The former was crashing, because it doesn't need ValueContext
and doesn't understand it. So, be sure to pass different property maps to these methods and include ValueContext
-ed numeric value in the one meant for index.add
:
Long value = 1L;
long node_id = inserter.createNode(
MapUtil.map("id", value, "other_prop", other_value));
index.add(node_id,
MapUtil.map("id", ValueContext.numeric( value ), "other_prop", other_value));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用的是哪个版本的 neo4j?它正在最新版本中运行
Which version of neo4j are you using? It's working in the latest release