Re: [TinkerPop] Help - Vertices inserted via Rexster - Unable to read vertices from Gremlin console gremlin.sh

282 views
Skip to first unread message

Stephen Mallette

unread,
Nov 14, 2012, 6:06:27 AM11/14/12
to gremli...@googlegroups.com
I'm not sure if you have some abridged code, but like Renato and the
post you reference, I don't see where you are committing the
transaction in your script from the Gremlin console. You need the
final line i added to your script:

confcass = new BaseConfiguration();
confcass.setProperty("storage.backend","cassandra");
confcass.setProperty("storage.hostname","localhost");
confcass.setProperty("port",9160);
confcass.setProperty("storage.keyspace","titan");
g = TitanFactory.open(confcass);
g.createKeyIndex('name', Vertex.class)
g.stopTransaction(SUCCESS)

As far as transactions in rexster go, a request to the standard REST
API is encapsulated within a transaction. So, if you POST a vertex
Rexster will commit that as a transaction.

Stephen

On Wed, Nov 14, 2012 at 5:51 AM, Jean-Armel Luce <jalu...@gmail.com> wrote:
> Hello,
>
> I am using titan with rexster and Cassandra :
>
> titan 0.1.0
> rexster 2.1.0
> cassandra 1.1.5 (1 single node in my VM)
>
> My rexster.xml file is attached to this mail
>
> Through Gremlin console (gremlin.sh), I have created an index on property
> name:
>
> confcass = new BaseConfiguration();
> confcass.setProperty("storage.backend","cassandra");
> confcass.setProperty("storage.hostname","localhost");
> confcass.setProperty("port",9160);
> confcass.setProperty("storage.keyspace","titan");
> g = TitanFactory.open(confcass);
> g.createKeyIndex('name', Vertex.class)
>
> Then, I have inserted a few vertices using REST requests, such as
> http://localhost:8182/graphs/titan&type=IA&name=IA_386653723
>
>
> I am able to query the vertices by their id from my browser :
> http://localhost:8182/graphs/titan/vertices/4
> returns :
> {"version":"2.1.0","results":{"name":"IA_386653723","type":"IA","_id":4,"_type":"vertex"},"queryTime":6.840465}
>
> From gremlin console (bin/gremlin.sh), I am able to query the vertex by its
> id, but I am not able to map it (error The value is already used by another
> vertex and the key is unique)
> gremlin> v = g.v(4)
> ==>v[4]
> gremlin> v.map
> The value is already used by another vertex and the key is unique
>
>
> And I am unable to query the vertices by their name, neither from my
> browser, nor from gremlin console.
>
> From gremlin console gremlin.sh, an error NoSuchElementException is thrown :
> gremlin> ia = g.V('name', 'IA_386653723').next()
> java.util.NoSuchElementException
> Display stack trace? [yN] n
>
>
> It looks that the index I have created thtrough gremlin.sh is not taken into
> account by Rexster.
>
> Maybe it is the same problem as Renato ?
> (https://groups.google.com/forum/?fromgroups=#!topic/gremlin-users/5dI0WObwQPE).
> In this case, I don't understand how to manage transactions with Rexster.
>
> Please, could you tell me what is wrong ?
>
> Thanks.
>
> Jean Armel
>
>
>
> --
>
>

Jean-Armel Luce

unread,
Nov 14, 2012, 7:29:41 AM11/14/12
to gremli...@googlegroups.com
Hello Stephen,

It is workiong now.

Thanks for your help.

For your information, I tried previously the command stopTransaction(true) as explained by Marko to Renato, but I got a syntax error.
And I didn't find anywhere this right syntax in the documentation. Maybe I didn't look at the right place ?

Jean Armel

Marko Rodriguez

unread,
Nov 14, 2012, 9:57:44 AM11/14/12
to gremli...@googlegroups.com
Hi,

For your information, I tried previously the command stopTransaction(true) as explained by Marko to Renato, but I got a syntax error.

The argument isn't a boolean, but a Conclusion enum.

graph.stopTransaction(SUCCESS) 
or
graph.stopTransaction(Conclusion.SUCCESS).

Note that there are plans to make this simply:
graph.commit()
graph.rollback()

Finally, see:

Good luck,
Marko.


--
 
 

Jean-Armel Luce

unread,
Nov 14, 2012, 12:47:18 PM11/14/12
to gremli...@googlegroups.com
Hi, Thanks Marko.

I am now able to create and query vertices. I have fun :-)

And now, I would like to have a unique key on property name.
I tried
name = g.makeType().name("name").unique()
g.createKeyIndex('name', Vertex.class)

and of course g.stopTransaction(SUCCESS);
(g.commit() doen't work. Probably my version is too old)

But I was able to create 2 different vertices with the same name. Is it normal.
Is it possible to create a unique index ?

Jean Armel

Jean-Armel Luce

unread,
Nov 16, 2012, 3:23:46 AM11/16/12
to gremli...@googlegroups.com
Found. A unique key is defined as below :

indexname = g.makeType().name("name").dataType(String.class).indexed().unique().functional().makePropertyKey();
g.stopTransaction(SUCCESS);

And now my property is unique :
gremlin> indexname.isUnique();
==>true

And now in my graph, it is imposible to have 2 different vertices with the same name :-)
Reply all
Reply to author
Forward
0 new messages