TitanDB - Build a property index in descending order by timestamp

故事扮演 提交于 2019-12-12 20:16:30

问题


TitanDB 1.0.0 (on top of DynamoDB)

Gremlin 3

I've got a set of vertices with a label a. I have a property of type long on those vertices which corresponds to the time in milliseconds from 1970 UTC (timestamp of when the vertex was created.) When I pull back those vertices I want to be able to pull them back in decsending order.

How can I create an index on that property in the decr order in Titan Management System?

Documentation seems vague on that.

Closest thing I found is

public RelationTypeIndex buildPropertyIndex(PropertyKey key, String name, Order sortOrder, PropertyKey... sortKeys)

But what do I put in as the key and sortKeys? I want to be able to pull the whole vertex ordered by the timestamp property

Edit: The only way I know of doing this at the minute is by duplicating that property on the edge and using a vertex centric index on the edge to increase the performance.


回答1:


I do something similar as I order by the release date of a particular product. If you want to execute order().by("Value", decr) efficiently then I highly recommend reading into mixed indices specified here. Mixed indices allow these operations to be done quickly.

An example of what you may be looking for:

TitanGraph graph = TitanFactory.open(config);
TitanManagement mgmt = graph.openManagement();
PropertyKey key = mgmt.makePropertyKey("TimeStamp").dataType(Long.class).make();
mgmt.buildIndex("timeStampIndex", Vertex.class).addKey(key).buildMixedIndex("search");
mgmt.commit();

The above index lets me execute the following query very quickly:

g.V().order().by("TimeStamp", decr);

Which gets me the time stamps in descending order. The above traversal will work without indexing but can be slow in large graphs.



来源:https://stackoverflow.com/questions/37299927/titandb-build-a-property-index-in-descending-order-by-timestamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!