Search code examples
janusgraph

Could not find a suitable index to answer graph query and graph scans are disabled


I am using JanusGraph with Cassandra as the back-end and Elasticsearch for indexing. When I try to send a query from my Python code to JanusGraph, it fails with timeout error and "Warning: please use indexing".

So I enabled this flag, query.force-index=true to check if the request is going to index or not and it throws the error

Could not find a suitable index to answer graph query and graph scans are disabled:

This is my Janusgraph config file,

storage.backend=cql
storage.cql.keyspace=education
storage.hostname=<host IP>
storage.port=9042
index.education.backend=elasticsearch
index.education.index-name=education
index.education.hostname=<elastic ip>
index.education.port=9200
index.education.elasticsearch.http.auth.type=BASIC
index.education.elasticsearch.http.auth.basic.username=<username>
index.education.elasticsearch.http.auth.basic.password=<password>

I define my schema for vertex and edge like this,

management.buildIndex("vertex", Vertex.class).addKey(management.getPropertyKey("profile_id"))
                .addKey(management.getPropertyKey("institute_name"))
                .addKey(management.getPropertyKey("company"))
                .buildMixedIndex("education");
        management.buildIndex("edge", Edge.class).addKey(management.getPropertyKey("passing_year"))
                .buildMixedIndex("education");

which makes my indexes,

education_vertex and education_edge

Then I insert my data, it is correctly inserted in Cassandra and Elastic.

When I query it using my Python script:

connection = DriverRemoteConnection(url='ws://<IP>:8182/gremlin', traversal_source='educationGraph')
g = traversal().withRemote(connection)
vertex = g.V().has("institute_name", "Saline Water Conversion Corporation").next()
print(vertex)

It fails with the error,

Could not find a suitable index to answer graph query and graph scans are disabled:

I am not sure what I am missing here.


Solution

  • The issue here is that a mixed index with two property keys is used. There is currently a bug in JanusGraph where the mixed index is not used in such a case if just one of the indexed property keys is used in the traversal and also only if exact equality is checked: janusgraph/janusgraph#3977.

    The index will however be used if either

    • both property keys (institute_name and company) are used in the traversal OR
    • a search predicate is used like textContains() for example.

    It should however also be noted that a composite index is better suited in general if you only want to search based on equality. The composite index is backed by the storage backend (Cassandra in this case) instead of the index backend (Elasticsearch) and will provide better performance for these kind of searches. Composite indexes however always require all indexed property keys. So you need to create a composite index with just institute_name for this traversal.

    This has also been asked in the GitHub discussions of the JanusGraph project.