问题
I have created indexes on two properties:
mgmt.buildIndex("userId", Vertex.class).addKey(mgmt.makePropertyKey("userId").dataType(Integer.class).make()).buildCompositeIndex();
mgmt.buildIndex("firstNameIndex", Vertex.class).addKey(mgmt.makePropertyKey("firstName").dataType(String.class).make()).buildCompositeIndex();
On Gremlin shell i can see the indexes have been created:
g.getIndexedKeys(Vertex.class)
==>userId
==>firstName
Now when i so query on vertices like simplest one:
gremlin> g.V()
18:33:42 WARN com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx - Query requires iterating over all vertices [()]. For better performance, use indexes
==>v[512]
==>v[256]
Or some complex one:
gremlin> g.V.has('firstName' ,CONTAINS,'Raj')
18:36:00 WARN com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx - Query requires iterating over all vertices [(firstName CONTAINS Raj)]. For better performance, use indexes
==>v[512]
Why its not using indexes for query.??
And is there any difference between creation of indexes and key indexes.? Any Explanation will be helpful.
Thanks
回答1:
Based on http://s3.thinkaurelius.com/docs/titan/1.0.0/indexes.html#index-mixed
Use a composite index for exact match index retrievals. Composite indexes do not require configuring or operating an external index system and are often significantly faster than mixed indexes.
As an exception, use a mixed index for exact matches when the number of distinct values for query constraint is relatively small or if one value is expected to be associated with many elements in the graph (i.e. in case of low selectivity). Use a mixed indexes for numeric range, full-text or geo-spatial indexing. Also, using a mixed index can speed up the order().by() queries.
In your case that it seems you are doing a full text search you need to use a mixed index, since composite ones are only used for exact matches.
You can find more info about full text search indices in: http://s3.thinkaurelius.com/docs/titan/1.0.0/index-parameters.html#_full_text_search
I don't see anywhere any difference between indices and key indices. Vertex-centric indices are different than property/key indices. Have a look at the link I provided. Hope this helps!
来源:https://stackoverflow.com/questions/33303123/titandb-not-using-indexes-for-query