Index on subquery not working

47 views
Skip to first unread message

Veerle

unread,
Aug 10, 2020, 9:34:11 AM8/10/20
to JanusGraph users
Hi,

I do have a graph with about 1 million vertexes and a many to many relation between those vertexes.
The vertexes are 

I created a mixed index 

management.buildIndex(indexName, Vertex.class)
                .addKey(management.getPropertyKey("property"))
                .indexOnly(road)
                .buildMixedIndex("search"); 

The index is working correctly, I can see it popping up in the profile output:
graph
.V()
.hasLabel(
"road")
.has("property", true)
.profile().next()

But when I want to have the same on the other side of the "connected" relation, the index is not used anymore.
graph
.V().both("connected")
.hasLabel("road")
.has("property", true)
        .profile().next()
Does someone know how I get the subquery to use the index?

Thanks a lot, Veerle

BO XUAN LI

unread,
Aug 10, 2020, 9:54:52 AM8/10/20
to janusgra...@googlegroups.com
Hi Veerle,

Try putting both(“connected”) after has(“property”, true).

Regards,
Boxuan

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/a9e313d7-cffa-442a-b2ca-f20339767103o%40googlegroups.com.

Veerle

unread,
Aug 10, 2020, 11:18:54 AM8/10/20
to JanusGraph users
Thanks for the answer but putting  has(“property”, true) before both(“connected”) changes the results of the query.

I actually simplefied my query a bit for my question here but what I want is a query that selects all relations where on one side the property is true and on the other side the property is false.
Something like this:

V()
        .hasLabel("road")
        .has("property", true)
        .both("connected")
        .hasLabel("road")
        .has("property", false)
.next()

The first part of the query uses the index, but the second part isn't.

Thanks, Veerle

BO XUAN LI

unread,
Aug 12, 2020, 12:08:48 PM8/12/20
to janusgra...@googlegroups.com
That’s pretty much expected. Index is used when you have a global lookup. In your case, the first has("property", true) is a global lookup, so it leverages index. The second has("property", true) is to check neighbors, or in other words, a local lookup, so it does not use index.

Depending on your data, there are a couple of things you can try:

1) You can build an index for edges, which indicates whether two endpoints have opposite properties.

2) You can use different edge labels to indicate different cases. Try with and without vertex-centric indexes.

3) Retrieve all vertices with property=true and all with property=false, do in-memory filtering in your application.

Hope this helps.

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages