Question

I'm using the neo4j batch operations endpoint. I want to index properties to an existing node if they have not been indexed before, ie. I'm using this endpoint, with the exception of using ?uniqueness=get_or_create flag.

It works, when when I'm issuing two such batch requests in a row for two different nodes, the second one never gets indexed!

Here is the payload for the the two batch requests:

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'
            }
        }
    ]

Any ideea as to why this is happening? If I remove uniqueness=get_or_create it works, but it's exactly what I want to achieve!

No correct solution

OTHER TIPS

See: http://docs.neo4j.org/chunked/stable/rest-api-batch-ops.html#rest-api-refer-to-items-created-earlier-in-the-same-batch-job and scroll down to the example in the payload that indexes a relationship.

As far as your REST API request payloads go, it looks like you're missing the id property in your JSON. Also, you do not need to explicitly set the uri to the full URI of your Neo4j instance, just use the relative path to your nodes.

Your request should look like this:

[
    {
        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
    }
]

That should resolve your issues.

It's worth noting that this will not create the user index. You will need to ensure your index is created in advance to running these batch operations. Also, you'll need to update the index using this same process if your property on the node changes. Let me know in the comments whether or not this resolves your issue.

Cheers,

Kenny

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top