Why my composite index does not work?

66 views
Skip to first unread message

Jenson

unread,
Aug 28, 2019, 10:38:33 PM8/28/19
to JanusGraph users
Hi, I am new to JanusGraph. I find that my composite index is not used for my query.
Here are my codes creating the schema:
final JanusGraphManagement management = getJanusGraph().openManagement();
management.makePropertyKey("custID").dataType(Long.class).make();
management.makeVertexLabel("PPAccount").make();
management.buildIndex("PPAccountIDIndex", Vertex.class).addKey(management.getPropertyKey("custID")).buildCompositeIndex();
management.commit();

Here is the query:
final Vertex bruceLi = g.addV("Account").property("custID", 11L).next();
g.tx().commit();

ManagementSystem.awaitGraphIndexStatus((JanusGraph) graph, "AccountIDIndex").call();

// look up vertex by name can use a composite index in JanusGraph
Traversal<Vertex, Map<Object, Object>> traversal = g.V().has("custID", 11L).valueMap();
while (traversal.hasNext()) {
    Object result = traversal.next();
    LOGGER.info(result.toString());
}

But I got following warring LOG:
10:31:30 WARN  org.janusgraph.graphdb.transaction.StandardJanusGraphTx - Query requires iterating over all vertices [(custID = 11)]. For better performance, use indexes

I debugged the code and confirmed the index was not used indeed.

My question is, why the composite index of 'custID' is not used for my query?

Thanks!
Junsheng

Oleksandr Porunov

unread,
Sep 4, 2019, 9:26:01 AM9/4/19
to JanusGraph users
Hi Junsheng

You should either ENABLE your index or REINDEX it (which automatically enables the index).

mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("PPAccountIDIndex"), SchemaAction.REINDEX).get()
mgmt.commit()

Also, I see that you have created "PPAccountIDIndex" but awaiting for "AccountIDIndex" which might be a simple misspell.

The typical flow is:
1) Build the index.
2) Commit the index.
3) Await till the index is registered.
4) Enable / Reindex the index. Which tells that the index can be now used by JanusGraph.


Best regards,
Oleksandr

Abhay Pandit

unread,
Sep 4, 2019, 9:46:35 AM9/4/19
to janusgra...@googlegroups.com
Hi Junsheng,

I am using Janusgraph since a year, here is a best practice I can suggest if you are working with indexes.
Before adding any vertex into janusgraph first create indexes.

If you have already added data change the keyspace name if you are using cassandra. Or delete every data from backend don't use g.V().drop(). Directly delete from backend. 
Then start with creating indexes first after then only start adding data.

Hope this helps.

Thanks,
Abhay

--
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/685b7216-498d-4f54-a403-8388e3e16d1f%40googlegroups.com.

Chris Forman Orth

unread,
Sep 4, 2019, 11:04:37 AM9/4/19
to JanusGraph users
Adding/Updating a composite index *IS* possible without dropping data, but I agree it can be a pain. Indexing is prone to stalling and it can take a few iterations of double-checking you have no other connections/transactions are open and reindexing.

-Chris


On Wednesday, September 4, 2019 at 9:46:35 AM UTC-4, Abhay Pandit wrote:
Hi Junsheng,

I am using Janusgraph since a year, here is a best practice I can suggest if you are working with indexes.
Before adding any vertex into janusgraph first create indexes.

If you have already added data change the keyspace name if you are using cassandra. Or delete every data from backend don't use g.V().drop(). Directly delete from backend. 
Then start with creating indexes first after then only start adding data.

Hope this helps.

Thanks,
Abhay

To unsubscribe from this group and stop receiving emails from it, send an email to janusgra...@googlegroups.com.

Jenson

unread,
Sep 5, 2019, 5:47:26 AM9/5/19
to janusgra...@googlegroups.com
Hi guys,
Thank you all for your help. The index is used for the query after re-index. 

Junsheng

Chris Forman Orth <cform...@gmail.com> 于2019年9月4日周三 下午11:04写道:
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/51dbc512-7211-43bb-a534-cb0ad6b5a976%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages