在JanusGraph上搜索多属性

时间:2018-03-08 19:46:34

标签: gremlin janusgraph

我对基数为多数的属性有疑问。当我使用具有基数列表或Set的属性时,我可以使用BerkleyDB搜索它吗?还是需要编入索引?我也可以对它进行NotIn和/或IN操作吗?例如,如果我的属性包含数据[1,2,3],我可以在[1,2,3]或[4]中进行[2] NotIn [1,2,3]

1 个答案:

答案 0 :(得分:0)

无论选择的存储后端如何,您都可以查询列表/集属性。您应该使用索引来提高性能,因为它需要没有图索引的完整扫描(您将看到WARN消息)。 without()操作还需要完整扫描。

gremlin> [ JanusGraph.version(), Gremlin.version() ]
==>0.2.0
==>3.2.6
gremlin> graph = JanusGraphFactory.build().
......1>     set('storage.backend', 'berkeleyje').
......2>     set('storage.directory', '/tmp/berkeleyje').
......3>     open()
==>standardjanusgraph[berkeleyje:/tmp/berkeleyje]

gremlin> mgmt = graph.openManagement()
==>org.janusgraph.graphdb.database.management.ManagementSystem@32b0876c
gremlin> nums = mgmt.makePropertyKey('nums').
......1>     dataType(Integer.class).cardinality(Cardinality.LIST).make()
==>nums
gremlin> numsIdx = mgmt.buildIndex('numsIdx', Vertex.class).
......1>     addKey(nums).buildCompositeIndex()
==>numsIdx
gremlin> mgmt.commit()
==>null

gremlin> g = graph.traversal()
==>graphtraversalsource[standardjanusgraph[berkeleyje:/tmp/berkeleyje], standard]
gremlin> g.addV().
......1>     property(VertexProperty.Cardinality.list, 'nums', 1).
......2>     property(VertexProperty.Cardinality.list, 'nums', 2).
......3>     property(VertexProperty.Cardinality.list, 'nums', 3)
==>v[4136]
gremlin> g.addV().property(VertexProperty.Cardinality.list, 'nums', 4)
==>v[8232]
gremlin> g.V().valueMap(true)
17:53:44 WARN  org.janusgraph.graphdb.transaction.StandardJanusGraphTx  - Query requires iterating over all vertices [()]. For better performance, use indexes
==>[label:vertex,nums:[1,2,3],id:4136]
==>[label:vertex,nums:[4],id:8232]
gremlin> g.V().has('nums', within(2))
==>v[4136]
gremlin> g.V().has('nums', without(4))
17:53:45 WARN  org.janusgraph.graphdb.transaction.StandardJanusGraphTx  - Query requires iterating over all vertices [(nums <> 4)]. For better performance, use indexes
==>v[4136]