Using the following commands to use indexes for better performance to query a node in titan db .
TitanManagement mgmt = graph.openManagement();
PropertyKey buyer = mgmt.makePropertyKey("buyer").dataType(String.class).cardinality(Cardinality.SINGLE).make();
TitanGraphIndex buyeri = mgmt.buildIndex("buyer", Vertex.class).addKey(buyer).buildCompositeIndex();
mgmt.setConsistency(buyeri, ConsistencyModifier.LOCK);
g.V().has("buyer","buyer", "buyer10").out("order_is").values("order").fill(list);
Using titan 1.0.0 , gremlin query language, while running this query it throws an error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293)
at java.lang.Thread.run(Thread.java:745)Caused by: com.thinkaurelius.titan.core.SchemaViolationException: Adding this property for key [~T$SchemaName] and value [rtbuyer] violates a uniqueness constraint [SystemIndex#~T$SchemaName]
at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.addProperty(StandardTitanTx.java:780)
at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.addProperty(StandardTitanTx.java:706)
at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.makeSchemaVertex(StandardTitanTx.java:836)
at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx.makePropertyKey(StandardTitanTx.java:856)
at com.thinkaurelius.titan.graphdb.types.StandardPropertyKeyMaker.make(StandardPropertyKeyMaker.java:86)
at pluradj.titan.tinkerpop3.example.JavaExample2.main(JavaExample2.java:56)
Updates as mentioned below in @jason Plurad answer
I have used
PropertyKey buyer = (!mgmt.containsPropertyKey("buyer")) ?
mgmt.makePropertyKey("buyer").dataType(String.class).cardinality(Cardinality.SINGLE).make() :
mgmt.getPropertyKey("buyer");
TitanGraphIndex buyeri = mgmt.getGraphIndex("buyeri");
if (buyeri == null) {
VertexLabel buyr = mgmt.getVertexLabel("buyer");
buyeri = mgmt.buildIndex("buyeri", Vertex.class).addKey(buyer).indexOnly(buyr). buildCompositeIndex();
mgmt.setConsistency(buyeri, ConsistencyModifier.LOCK);
}
mgmt.commit();
st=System.currentTimeMillis();
g.V().has("buyer","buyer", "buyer10").out("order_is").values("order").fill(list);
System.out.println(System.currentTimeMillis()-st +"millllli");
Using the following code to index buyer , to make searching vertex faster , but dont know why it is not indexing is not working , Can anyone fix this please.
i have read the documentation of titan db indexing part but i guess it is not working ..