0

我正在使用 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它就可以了,但这正是我想要实现的!

4

1 回答 1

1

请参阅:http ://docs.neo4j.org/chunked/stable/rest-api-batch-ops.html#rest-api-refer-to-items-created-earlier-in-the-same-batch-job和向下滚动到有效负载中索引关系的示例。

就您的 REST API 请求有效负载而言,您的 JSON 中似乎缺少该id属性。此外,您无需显式设置uriNeo4j 实例的完整 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索引。您需要确保提前创建索引才能运行这些批处理操作。此外,如果节点上的属性发生更改,您将需要使用相同的过程更新索引。在评论中让我知道这是否解决了您的问题。

干杯,

肯尼

于 2013-12-11T05:27:31.803 回答