neo4j批处理操作get_or_create标志将覆盖具有不同id的现有节点



我使用的是neo4j批处理操作端点。如果以前没有对现有节点的属性进行索引,我想将其索引到现有节点,即,除了使用?uniqueness=get_or_create标志外,我正在使用此端点。

当我为两个不同的节点连续发出两个这样的批处理请求时,第二个节点永远不会被索引,这是有效的!

以下是两个批处理请求的有效载荷:

FIRST ONE:
[
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: 'http: //localhost: 7474/db/data/node/2388',
            key: 'registeredInShop',
            value: '52a5f4e19e3fc8406a000006'
        }
    },
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: 'http: //localhost: 7474/db/data/node/2388',
            key: 'idInShop',
            value: '1'
        }
    },
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: 'http: //localhost: 7474/db/data/node/2388',
            key: 'email',
            value: 'me@shop.com'
        }
    },
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: 'http: //localhost: 7474/db/data/node/2388',
            key: 'createdOn',
            value: 1386607841880
        }
    },
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: 'http: //localhost: 7474/db/data/node/2388',
            key: 'attributes_isSpam',
            value: false
        }
    },
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: 'http: //localhost: 7474/db/data/node/2388',
            key: 'attributes_isHardBounced',
            value: false
        }
    },
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: 'http: //localhost: 7474/db/data/node/2388',
            key: 'attributes_isSubscribedAlerts',
            value: true
        }
    },
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: 'http: //localhost: 7474/db/data/node/2388',
            key: 'attributes_isSubscribed',
            value: true
        }
    },
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: 'http: //localhost: 7474/db/data/node/2388',
            key: 'attributes_isCustomer',
            value: false
        }
    },
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: 'http: //localhost: 7474/db/data/node/2388',
            key: 'id',
            value: '52a5f4e19e3fc8406a000008'
        }
    }
]


// SECOND ONE

[
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: 'http: //localhost: 7474/db/data/node/2390',
            key: 'registeredInShop',
            value: '52a5f4e19e3fc8406a000006'
        }
    },
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            method: 'POST',
            to: '/index/node/users?uniqueness=get_or_create',
            body: {
                uri: 'http: //localhost: 7474/db/data/node/2390',
                key: 'email',
                value: 'me2@shop.com'
            }
        },
        {
            method: 'POST',
            to: '/index/node/users?uniqueness=get_or_create',
            body: {
                uri: 'http: //localhost: 7474/db/data/node/2390',
                key: 'createdOn',
                value: 1386607842460
            }
        },
        {
            method: 'POST',
            to: '/index/node/users?uniqueness=get_or_create',
            body: {
                uri: 'http: //localhost: 7474/db/data/node/2390',
                key: 'attributes_isSpam',
                value: false
            }
        },
        {
            method: 'POST',
            to: '/index/node/users?uniqueness=get_or_create',
            body: {
                uri: 'http: //localhost: 7474/db/data/node/2390',
                key: 'attributes_isHardBounced',
                value: false
            }
        },
        {
            method: 'POST',
            to: '/index/node/users?uniqueness=get_or_create',
            body: {
                uri: 'http: //localhost: 7474/db/data/node/2390',
                key: 'attributes_isSubscribedAlerts',
                value: true
            }
        },
        {
            method: 'POST',
            to: '/index/node/users?uniqueness=get_or_create',
            body: {
                uri: 'http: //localhost: 7474/db/data/node/2390',
                key: 'attributes_isSubscribed',
                value: true
            }
        },
        {
            method: 'POST',
            to: '/index/node/users?uniqueness=get_or_create',
            body: {
                uri: 'http: //localhost: 7474/db/data/node/2390',
                key: 'attributes_isCustomer',
                value: false
            }
        },
        {
            method: 'POST',
            to: '/index/node/users?uniqueness=get_or_create',
            body: {
                uri: 'http: //localhost: 7474/db/data/node/2390',
                key: 'id',
                value: '52a5f4e29e3fc8406a000016'
            }
        }
    ]

你知道为什么会发生这种事吗?如果我删除uniqueness=get_or_create,它会起作用,但这正是我想要实现的!

请参阅:http://docs.neo4j.org/chunked/stable/rest-api-batch-ops.html#rest-api引用先前在同一批处理作业中创建的项,并向下滚动到索引关系的有效负载中的示例。

就REST API请求有效负载而言,JSON中似乎缺少id属性。此外,您不需要显式地将uri设置为Neo4j实例的完整URI,只需使用节点的相对路径即可。

你的请求应该是这样的:

[
    {
        method: 'POST',
        to: '/index/node/users?uniqueness=get_or_create',
        body: {
            uri: '/node/2388',
            key: 'registeredInShop',
            value: '52a5f4e19e3fc8406a000006'
        },
        id: 2388
    },
    {
        method: 'POST',
        to: '/index/node/users',
        body: {
            uri: '/node/2388',
            key: 'idInShop',
            value: '1'
        },
        id: 2388
    }
]

这应该能解决你的问题。

值得注意的是,这不会创建user索引。您需要确保在运行这些批处理操作之前创建索引。此外,如果节点上的属性发生更改,则需要使用相同的过程更新索引。请在评论中告诉我这是否解决了您的问题。

干杯,

Kenny

相关内容

  • 没有找到相关文章

最新更新