tinkerpop3 - Indexing fails on enabling force index in Titan/Janus -
i've written junit test check against generate-modern.groovy graph if marko exists.
gremlin query being
"g.v().has('name','marko')";
as can see in generate-modern.groovy file indexing applied on name property of person. later made following
query.force-index=true
property true in dynamodb.properties file blocks whole graph scan thereby making indexing mandatory. throws me following exception
org.janusgraph.core.janusgraphexception: not find suitable index answer graph query , graph scans disabled: [(name = marko)]:vertex
the above exception raised following standardjanusgraphtx class's method
@override public iterator<janusgraphelement> execute(final graphcentricquery query, final jointindexquery indexquery, final object exeinfo, final queryprofiler profiler) { iterator<janusgraphelement> iter; if (!indexquery.isempty()) { list<queryutil.indexcall<object>> retrievals = new arraylist<queryutil.indexcall<object>>(); (int = 0; < indexquery.size(); i++) { final jointindexquery.subquery subquery = indexquery.getquery(i); retrievals.add(new queryutil.indexcall<object>() { @override public collection<object> call(int limit) { final jointindexquery.subquery adjustedquery = subquery.updatelimit(limit); try { return indexcache.get(adjustedquery, new callable<list<object>>() { @override public list<object> call() throws exception { return queryprofiler.profile(subquery.getprofiler(), adjustedquery, q -> indexserializer.query(q, txhandle)); } }); } catch (exception e) { throw new janusgraphexception("could not call index", e.getcause()); } } }); } list<object> resultset = queryutil.processintersectingretrievals(retrievals, indexquery.getlimit()); iter = com.google.common.collect.iterators.transform(resultset.iterator(), getconversionfunction(query.getresulttype())); } else { if (config.hasforceindexusage()) throw new janusgraphexception("could not find suitable index answer graph query , graph scans disabled: " + query); log.warn("query requires iterating on vertices [{}]. better performance, use indexes", query.getcondition()); queryprofiler sub = profiler.addnested("scan"); sub.setannotation(queryprofiler.query_annotation,indexquery); sub.setannotation(queryprofiler.fullscan_annotation,true); sub.setannotation(queryprofiler.condition_annotation,query.getresulttype()); switch (query.getresulttype()) { case vertex: return (iterator) getvertices().iterator(); case edge: return (iterator) getedges().iterator(); case property: return new vertexcentricedgeiterable(getinternalvertices(),relationcategory.property).iterator(); default: throw new illegalargumentexception("unexpected type: " + query.getresulttype()); } } return iter; } };
as can observe method exception raised when jointindexquery object empty(arraylist being empty) , force index true.
the problem why list empty? when have specified indexing query against name property in generate-modern.groovy while querying junit test.this works fine meaning list not empty when same data being preloaded gremlin server same file.
the personbyname
index definition uses label constraint.
def personbyname = mgmt.buildindex("personbyname", vertex.class).addkey(name).indexonly(person).buildcompositeindex()
in order take advantage of index, must use label , property. example:
g.v().has('person', 'name', 'marko')
you can read more in janusgraph documentation http://docs.janusgraph.org/latest/indexes.html#_label_constraint
Comments
Post a Comment