Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

titan make unique vertex based on property key

I want to create a vertexs that do not have duplicate property, e.g., name

I followed the page https://github.com/thinkaurelius/titan/wiki/Vertex-Centric-Indices

However, it does not work for me

gremlin>g.makeType().name('dom').unique(OUT).dataType(String.class).indexed(Vertex.class).makePropertyKey()
==>v[36028797018965714]
gremlin> u2 = g.addVertex([dom:'def.com'])
==>v[480020]
gremlin> u2 = g.addVertex([dom:'def.com'])
==>v[480024]

Can I just have one vertext created for the same dom property?

Thanks in advance

like image 994
yzhang Avatar asked Dec 02 '25 04:12

yzhang


1 Answers

You need to define your type as unique(BOTH). You can read more about types here.

gremlin> g = TitanFactory.open('/tmp/titan')
==>titangraph[local:/tmp/titan]
gremlin> g.makeType().name('dom').unique(BOTH).dataType(String.class).indexed(Vertex.class).makePropertyKey()
==>v[36028797018963978]
gremlin> g.commit()
==>null
gremlin> u2 = g.addVertex([dom:'def.com'])
==>v[4]
gremlin> u2 = g.addVertex([dom:'def.com'])
The given value is already used as a property and the property key is defined as in-unique
Display stack trace? [yN] n
gremlin>
like image 90
stephen mallette Avatar answered Dec 06 '25 06:12

stephen mallette



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!