Map options with pooling or creating a batch operation through the client?

Is there any way to match params passed using Merge?

Ideally, this is what I want to do:

Merge node (create, if it does not exist, or update all node properties - dynamic)

MERGE (c: Label {Id: {map} .Id}) SET c = {map}

This can be done easily when the map is the only object and you are updating only one node, but I would like it to be possible as a mass operation.
Go to the list and get this automatic card.

Of course, I do not think that this is currently possible using Cypher Merge, but this can be done using the Ratch API Batch methods, but it is not clear how to create a package using Neo4jClient.

If possible, how could a batch of merger operations be organized? I could list the list and for each object add a merge operation to the package. Then complete the package in its entirety.

Any help would be awesome!


Update So, a strange side effect is when I run this code:

        createUniqueConstraint(label, PK_Field); 
        string propKey = label + "s" ;

        //string createstr = string.Format("(e:{0} {{{1}}})", label, propKey);
        string strForEach = string.Format("(n in {{{0}}} |  MERGE (c:{1} {{{2} : n.{2}}}) SET c = n)",
            propKey, label, PK_Field);

        foreach (var entities in Neo4jDataRepository.Batch(list, 1000))
        {
            var query = client
                            .Cypher
                            .ForEach(strForEach)
                            .WithParam(propKey, entities.ToList());

            query.ExecuteWithoutResults();
            Debug.WriteLine("Batch passed for " + label + " ("+list.Count()+" items)");
            break;
        }

This works fine (sort of). I have linked nodes that also contain a property with the same name as PK_Field, and I get nodes with a single property instead of the whole object.

Example: Contact {ContactId: 1, name: "David"} is one model of the ContactMembership object {ContactMembershipId: 1, ContactId: 1, ContactMembershipTypeId: 1} ContactMembershipType {ContactMembershipType: 1, name: "User"}

/ , Merge. , , , ContactMembership :

 public void CreateNewRelationshipsFromMatrix<T>(IEnumerable<T> relationshipMatrix,   string IDFieldLeft, string IDFieldRight)
        where T : BaseModel
    {
        string entityName = GetTypeName(default(T)); //i.e. ContactAddress

        string merge1 = string.Format("(c:{0} {{{1}:row.{2}}})", IDFieldLeft.Replace("Id", ""), IDFieldLeft, IDFieldLeft);
        string merge2 = string.Format("(a:{0} {{{1}:row.{2}}})", IDFieldRight.Replace("Id", ""), IDFieldRight, IDFieldRight);
        string merge3 = string.Format("(c)-[r:{0}Link]->(a)", entityName);

        string uniqueRelationshipSetter = " ON CREATE SET r.weight=1 ON MATCH SET r.weight = r.weight + 1 ";

        foreach (var list in Neo4jDataRepository.Batch(relationshipMatrix, 1000))
        {
            var q1 = client.Cypher.Merge(merge1);
            var q2 = client.Cypher.Merge(merge2);
            var q3 = client.Cypher.Merge(merge3);

            var query = client
                        .Cypher
                        .WithParam("coll", list.ToList())
                        .ForEach("(row in {coll} | " +
                        q1.Query.QueryText + " " +
                        q2.Query.QueryText + " " +
                        q3.Query.QueryText + ")");
            query.ExecuteWithoutResults();
        }

    }

, ( ) : ContactId . MATCH (n: Contact) - [: ContactMembership] - (t) ContactId n, .

MATCH (n) - [: ContactMembership] - (t) t n.

, .

0
1
FOREACH (n in {set} | MERGE (c:Label {Id : n.Id}) SET c = n)

http://docs.neo4j.org/chunked/stable/query-foreach.html

. , , , - Cypher:

LOAD CSV WITH HEADERS FROM 'file://c:/temp/input.csv' AS n
MERGE (c:Label { Id : n.Id })
SET c = n

https://github.com/davidegrohmann/neo4j/blob/2.1-fix-resource-failure-load-csv/community/cypher/cypher/src/test/scala/org/neo4j/cypher/LoadCsvAcceptanceTest.scala

+1

Source: https://habr.com/ru/post/1535454/


All Articles