neo4j - 如何通过 rest api 运行 1000 个对象的查询 [英] neo4j - how to run queries with 1000 objects via rest api

查看:85
本文介绍了neo4j - 如何通过 rest api 运行 1000 个对象的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要运行 1000 个对象的查询.使用 /batch 端点我可以让它工作,但速度太慢(300 个项目 30 秒).

I'm need run queries with 1000 objects. Using /batch endpoint I can get this to work but is too slow (30 seconds with 300 items).

所以我正在尝试与此文档页面中所述相同的方法:http://docs.neo4j.org/chunked/2.0.1/rest-api-cypher.html#rest-api-create-mutiple-nodes-with-properties

So I'm trying the same approach as said in this docs page: http://docs.neo4j.org/chunked/2.0.1/rest-api-cypher.html#rest-api-create-mutiple-nodes-with-properties

将此 JSON POST 到 http://localhost:7474/db/data/cypher

POST this JSON to http://localhost:7474/db/data/cypher

{
    "params": {
        "props": [
            {
                "_user_id": "177032492760",
                "_user_name": "John"
            },
            {
                "_user_id": "177032492760",
                "_user_name": "Mike"
            },
            {
                "_user_id": "100007496328",
                "_user_name": "Wilber"
            }
        ]
    },
    "query": "MERGE (user:People {id:{_user_id}}) SET user.id = {_user_id}, user.name = {_user_name} "
}

问题是我收到此错误:

{ message: 'Expected a parameter named _user_id',
  exception: 'ParameterNotFoundException',
  fullname: 'org.neo4j.cypher.ParameterNotFoundException',
  stacktrace:
  ...

也许这仅适用于 CREATE 查询,如文档页面所示?

Maybe this works only with CREATE queries, as showing in the docs page?

推荐答案

在 ON CREATE SET 中使用 FOREACH 和 MERGE:

Use FOREACH and MERGE with ON CREATE SET:

 FOREACH (p in {props} | 
    MERGE (user:People {id:{p._user_id}}) 
      ON CREATE  user.name = {p._user_name})

将此 JSON POST 到 http://localhost:7474/db/data/cypher

POST this JSON to http://localhost:7474/db/data/cypher

{
    "params": {
        "props": [
            {
                "_user_id": "177032492760",
                "_user_name": "John"
            },
            {
                "_user_id": "177032492760",
                "_user_name": "Mike"
            },
            {
                "_user_id": "100007496328",
                "_user_name": "Wilber"
            }
        ]
    },
    "query": "FOREACH (p in {props} | MERGE (user:People {id:{p._user_id}}) ON CREATE  user.name = {p._user_name}) "
}

这篇关于neo4j - 如何通过 rest api 运行 1000 个对象的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆