I tested the solution provided by @asnozzle above. (Server 5.7.0.11, Java client 5.1.11). (I put PK:pk as k:v in mapBin. I suppose you want it in its own bin.)
package com.aerospike;
import com.aerospike.client.*;
import com.aerospike.client.policy.WritePolicy;
import com.aerospike.client.cdt.MapPolicy;
import com.aerospike.client.cdt.CTX;
import com.aerospike.client.cdt.MapReturnType;
import com.aerospike.client.cdt.MapOrder;
import com.aerospike.client.cdt.ListOperation;
import com.aerospike.client.cdt.MapOperation;
public class TestExample {
public static void main(String[] args) throws Exception {
TestExample ce = new TestExample();
ce.runExample();
return;
}
public void runExample() throws Exception {
AerospikeClient client = new AerospikeClient("127.0.0.1", 3000);
insertTuple(client, "pk", "attr1", "a1v1");
insertTuple(client, "pk", "attr1", "a1v2");
insertTuple(client, "pk", "attr2", "a2v1");
insertTuple(client, "pk", "attr2", "a2v2");
insertTuple(client, "pk", "attr2", "a2v3");
insertTuple(client, "pk", "attr3", "a3v1");
}
private void insertTuple(AerospikeClient client, String s1, String s2, String s3) throws Exception {
Key key = new Key("test", "testset", "k1");
Record record = client.get(null, key);
System.out.println("\nInitial Record: " + record);
// Insert tuple data
WritePolicy wPolicy = new WritePolicy(client.writePolicyDefault);
MapPolicy mPolicy = new MapPolicy();
client.operate(wPolicy, key,
MapOperation.put(mPolicy, "mapBin", Value.get("PK"), Value.get(s1)),
ListOperation.append("mapBin", Value.get(s3), CTX.mapKeyCreate(Value.get(s2), MapOrder.UNORDERED))
);
record = client.get(null,key);
System.out.println("Get Record: " + record);
}
}
And the output is:
Initial Record: null
Get Record: (gen:1),(exp:386490396),(bins:(mapBin:{attr1=[a1v1], PK=pk}))
Initial Record: (gen:1),(exp:386490396),(bins:(mapBin:{attr1=[a1v1], PK=pk}))
Get Record: (gen:2),(exp:386490396),(bins:(mapBin:{attr1=[a1v1, a1v2], PK=pk}))
Initial Record: (gen:2),(exp:386490396),(bins:(mapBin:{attr1=[a1v1, a1v2], PK=pk}))
Get Record: (gen:3),(exp:386490396),(bins:(mapBin:{attr2=[a2v1], attr1=[a1v1, a1v2], PK=pk}))
Initial Record: (gen:3),(exp:386490396),(bins:(mapBin:{attr2=[a2v1], attr1=[a1v1, a1v2], PK=pk}))
Get Record: (gen:4),(exp:386490396),(bins:(mapBin:{attr2=[a2v1, a2v2], attr1=[a1v1, a1v2], PK=pk}))
Initial Record: (gen:4),(exp:386490396),(bins:(mapBin:{attr2=[a2v1, a2v2], attr1=[a1v1, a1v2], PK=pk}))
Get Record: (gen:5),(exp:386490396),(bins:(mapBin:{attr2=[a2v1, a2v2, a2v3], attr1=[a1v1, a1v2], PK=pk}))
Initial Record: (gen:5),(exp:386490396),(bins:(mapBin:{attr2=[a2v1, a2v2, a2v3], attr1=[a1v1, a1v2], PK=pk}))
Get Record: (gen:6),(exp:386490396),(bins:(mapBin:{PK=pk, attr2=[a2v1, a2v2, a2v3], attr1=[a1v1, a1v2], attr3=[a3v1]}))