Query on edge property gives unexplicable results

I’m currently stuck trying to understand why this query:

"SELECT expand( both(‘Distance’).outE()[‘Entity similarity’ > 1 ] ) FROM " + v.getIdentity()

Distance{out:#28:18,in:#31:18,Entity similarity:0.0812547547476632}
Distance{out:#28:18,in:#32:18,Entity similarity:0.05788279431206844}
Distance{out:#29:18,in:#30:18,Entity similarity:0.1784653663635254}
Distance{out:#29:18,in:#31:18,Entity similarity:0.1784653663635254}

While this query:

"SELECT expand( both(‘Distance’).outE()[‘Entity similarity’ < 1 ] ) FROM " + v.getIdentity()

gives 0 results

In other words, the “Entity similarity” field value is apparently not related at all with the query that specifies < or > 1.

How should I interpret this result?

What is the correct way to query a vertex’s neighbors by filtering them depending on the value of some edge properties?

I’m using versino 3.0.19


Hi @Maverick

I think you are just evaluating the string ‘Entity similarity’ and not the edge field.

Try to replace the single quotes with backticks:

SELECT expand( both(‘Distance’).outE()[`Entity similarity` < 1 ] ) FROM x



Thanks for your quick reply

I had already tried with the backticks, but made another attempt: in this case no results at all are retrieved.

Hi @Maverick

I think I need a sample db to reproduce the problem…



Hi Luigi,

Here is a sample.

package eu.snt.odbtest;

import com.orientechnologies.orient.core.db.ODatabasePool;
import com.orientechnologies.orient.core.db.ODatabaseType;
import com.orientechnologies.orient.core.db.OrientDB;
import com.orientechnologies.orient.core.db.OrientDBConfig;
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
import com.orientechnologies.orient.core.record.OEdge;
import com.orientechnologies.orient.core.record.OVertex;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;

public class ODBTest 
    public static void main( String[] args )
    	new ODBTest().run();
    ODatabaseDocument session;
    public void run() {
	    OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
	    String dbname = "test";
	    OrientDB orientDB = new OrientDB("memory:", dbConfig);
	    orientDB.createIfNotExists( dbname, ODatabaseType.MEMORY );
	    session = new ODatabasePool( orientDB, dbname, "admin", "admin" ).acquire();
	    session.createVertexClass( "Entry" );
	    session.createEdgeClass( "Distance" );
	    OVertex v1 = addVertex( "Vertex 1" );
	    OVertex v2 = addVertex( "Vertex 2" );
	    addEdge( v1, v2, 0.2 );
	    query( v1 );
	private OVertex addVertex( String prop ) {
		OVertex v = session.newVertex( "Entry" );
		v.setProperty( "myProp", prop );
		return v;
	public void addEdge( OVertex v1, OVertex v2, double distance ) {
		OEdge edge = session.newEdge( v1, v2, "Distance" );
		edge.setProperty( "Entity similarity", distance );

	public void query( OVertex v ) {
		for( OIdentifiable id : new OSQLSynchQuery<ODocument>(
				"SELECT expand(" 
					+ "both('Distance').bothE()['Entity similarity' > 1 ]"
				+ ") FROM " + v.getIdentity()
		      )) {
			ODocument doc = session.getRecord( id );
			System.out.println( doc );

Hi @luigidellaquila,

Did you have any chance to check the code? I ran out of ideas…