How can i keep the vertex which i want to add is unique?


huu...@...
 

Hi, all:

       How can i keep the vertex which i want to add is unique?  get and add?  whether have any other methods to add unique vertex ?


Jason Plurad <plu...@...>
 

Check out the documentation for creating a unique composite index.

Here's an example Gremlin Console session which creates a unique composite index on name. When you attempt to set a non-unique name, it will throw a SchemaViolationException.

gremlin> graph = JanusGraphFactory.open('inmemory')
==>standardjanusgraph[inmemory:[127.0.0.1]]
gremlin
> mgmt = graph.openManagement()
==>org.janusgraph.graphdb.database.management.ManagementSystem@2eadc9f6
gremlin
> name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(Cardinality.SINGLE).make()
==>name
gremlin
> nameIndex = mgmt.buildIndex('nameIndex', Vertex.class).addKey(name).unique().buildCompositeIndex()
==>nameIndex
gremlin
> mgmt.commit()
==>null
gremlin
> graph.addVertex('name', 'huupon')
==>v[4184]
gremlin
> graph.addVertex('name', 'huupon')
Adding this property for key [name] and value [huupon] violates a uniqueness constraint [nameIndex]


-- Jason


On Wednesday, June 21, 2017 at 4:34:22 AM UTC-4, huupon wrote:
Hi, all:

       How can i keep the vertex which i want to add is unique?  get and add?  whether have any other methods to add unique vertex ?


huu...@...
 

Thank you Jason,  and  we have many of duplicated vertex,  How can I do  with janusgraph more effectively?  We query a vertex and judge the existence then  decide  what  next to do, that's very low effective especially when we need to import amount of vertex and edge.

在 2017年6月23日星期五 UTC+8上午11:47:34,Jason Plurad写道:

Check out the documentation for creating a unique composite index.

Here's an example Gremlin Console session which creates a unique composite index on name. When you attempt to set a non-unique name, it will throw a SchemaViolationException.

gremlin> graph = JanusGraphFactory.open('inmemory')
==>standardjanusgraph[inmemory:[127.0.0.1]]
gremlin
> mgmt = graph.openManagement()
==>org.janusgraph.graphdb.database.management.ManagementSystem@2eadc9f6
gremlin
> name = mgmt.makePropertyKey('name').dataType(String.class).cardinality(Cardinality.SINGLE).make()
==>name
gremlin
> nameIndex = mgmt.buildIndex('nameIndex', Vertex.class).addKey(name).unique().buildCompositeIndex()
==>nameIndex
gremlin
> mgmt.commit()
==>null
gremlin
> graph.addVertex('name', 'huupon')
==>v[4184]
gremlin
> graph.addVertex('name', 'huupon')
Adding this property for key [name] and value [huupon] violates a uniqueness constraint [nameIndex]


-- Jason

On Wednesday, June 21, 2017 at 4:34:22 AM UTC-4, huupon wrote:
Hi, all:

       How can i keep the vertex which i want to add is unique?  get and add?  whether have any other methods to add unique vertex ?


tinajo...@...
 

Please help me on this.... I have same issue.
First I created a index with unique constraint after that I want to remove that unique constraint and do reindex on that.
So please tell me the solution.
thanks in advance.