Neo4j 中批量插入期间的数字索引

发布于 2024-11-28 20:29:48 字数 1640 浏览 0 评论 0原文

我正在将节点和关系批量插入到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半岛未凉 2024-12-05 20:29:48

您使用的是哪个版本的 neo4j?它正在最新版本中运行

Which version of neo4j are you using? It's working in the latest release

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文