The following query should return at most limit
vertices with the label REPOSITORY
, that were last updated before minLastUpdated
and are not of type FILE_UPLOAD
, unless the NEEDS_UPDATE
flag is set.
g.V()
.hasLabel(VertexLabel.REPOSITORY.name())
.has(PropertyKey.INDEXED_LABEL.name(), VertexLabel.REPOSITORY.name())
.has(PropertyKey.LAST_UPDATED.name(), P.lt(minLastUpdated))
.or(__.not(__.has(PropertyKey.TYPE.name(), RepositoryType.FILE_UPLOAD.name())),
__.has(PropertyKey.NEEDS_UPDATE.name(), true))
.limit(limit);
To avoid a full graph scan, I have created the following indexes on properties INDEXED_LABEL
, TYPE
and NEEDS_UPDATE
, a composite index combining all three and a mixed index:
//By Label
mgmt.buildIndex("byIndexedLabel", Vertex.class)
.addKey(indexedLabelKey)
.buildCompositeIndex();
//By Type
mgmt.buildIndex("byType", Vertex.class)
.addKey(typeKey)
.buildCompositeIndex();
//By Needs Update
mgmt.buildIndex("byNeedsUpdate", Vertex.class)
.addKey(needsUpdateKey)
.buildCompositeIndex();
//Combination of the three
mgmt.buildIndex("byIndexedLabelTypeAndNeedsUpdate", Vertex.class)
.addKey(indexedLabelKey)
.addKey(typeKey)
.addKey(needsUpdateKey)
.buildCompositeIndex();
//Mixed Index
mgmt.buildIndex("repositoryByTypeAndLastUpdated", Vertex.class)
.addKey(indexedLabelKey, Mapping.STRING.asParameter())
.addKey(lastUpdatedKey)
.indexOnly(repositoryLabel)
.buildMixedIndex("search");
Yet when executing the query, I get this warning:
WARN - StandardTitanTx$6: Query requires iterating over all vertices [()]. For better performance, use indexes
Sidenotes
- The Vertex Labels are defined within the same transaction as the indexes, which means all indexes should be available immediately.
PropertyKey
andVertexLabel
are my ownenums
.- The keys used during index setup are all instances of
com.thinkaurelius.titan.core.PropertyKey
which I added earlier. - All properties have the data type
String
except forNEEDS_UPDATE
, which is aBoolean
.
Environment
- Titan 1.0.0
- TinkerPop 3.0.1
- Elastic Search 1.0.0
- Berkeley Storage Backend
Thanks for any suggestions you might have.