Thanks Craig.

I've started with that, but had a warning in the server about too many 
nodes in the query and it suggested I should use an index. I guess it did 
not fell exactly on my composed index and it ran the query directly. I'll 
check the source code later maybe I can figure out if it can actually use 
composed indexes and how.

In the mean time, I settled for running the sql query with a command:
String query = "select rid from index:A.s_i where key = [?, ?]";
graph.command(new OCommandSQL(query)).execute('A', 1);

this seems to work OK for now, although I have issues understanding how 
transactions are handled here for a noTx graph. But that is another issue.


On Monday, April 27, 2015 at 3:59:21 PM UTC+3, Craig Trader wrote:
>
> From a quick inspection of the source code 
> <https://github.com/orientechnologies/orientdb/blob/master/graphdb/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java>,
>  
> it would appear that that method is intended for use with single-part keys 
> only. The only method that appears to handle multiple key-value pairs would 
> be getVertices.  Try using this call instead:
>
> graph.getVertices( "A", new Object[]{"s","i"}, new Object[]{"A", 1 } )
>
> A quick read of the code implies that getVertices() will loop through the 
> available indexes and use a matching index, if available.
>
> - Craig -
>
> On Mon, Apr 27, 2015 at 3:23 AM, Adrian Mihalcea <[email protected] 
> <javascript:>> wrote:
>
>> Hi all,
>>
>> I've been trying to use the Java API to obtain indexed records and got 
>> myself in a bit of a problem. 
>>
>> I'm using version 2.0.8
>>
>> on OrientBaseGraph there is a method called getVertexByKey.
>>
>> javadoc for it says:
>>
>> *Vertex 
>> com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.getVertexByKey(String 
>> iKey, Object iValue)*
>>
>>
>> *Lookup for a vertex by id using an index.*
>> *Example: Vertex v = getVertexByIndex("V.name", "name", "Jay"); *
>> *Parameters:*
>> * iKey Name of the indexed property*
>> * iValue Field value*
>> *Returns:*
>> * Vertex instance if found, otherwise null*
>>
>> Apart from the apparent wrong example in JavaDoc, that refers to a non 
>> existent (probably older) getVertexByIndex method, the method seems to work 
>> fine in these conditions:
>> 1. index is unique
>> 2. index is created for a single field
>>
>> while first point is understandable as the method returns a single Vertex 
>> node, for the second point I need help in expressing the key for indexes on 
>> multiple fields.
>>
>> I have a node A with two fields s of type string and i of type integer. 
>> Index name is A.s_i
>> In the web UI whenever I write the query as:
>> select rid from index:A.s_i where key = ['A', 1]
>> the query succeeds and has expected result.
>>
>> if I attempt to retrieve the value with the same key from java, using 
>> getVertexByKey, I don't get any results:
>>
>> My attempts so far in writing the key are:
>>
>> graph.getVertexByIndex("A.s_i", new Object[]{"A", 1})
>> graph.getVertexByIndex("A.s_i", "['A',1]")
>> also tried with a List<Object> as key, but no results.
>>
>> Looks like I'm fighting the API so it is probably something that I'm 
>> doing wrong, but I'm a bit lost about what is the right path. Could you 
>> please help me with this?
>>
>> Thank you,
>> Adrian
>>
>> -- 
>>
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "OrientDB" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to