JanusGraph·How to represent, write or query an array in JanusGraph?
JanusGraph如何表示一个定点具有多个同名属性
JanusGraph定点的属性值不支持数组数据类型
collection的使用
If you are using Elasticsearch then you can index properties with SET and LIST cardinality. For instance:
以下Java函数中的codes在gremlin-server中当做
If you are using Elasticsearch then you can index properties with SET and LIST cardinality(基数,不明白什意思). For instance:
mgmt = graph.openManagement()
nameProperty = mgmt.makePropertyKey("names").dataType(String.class).cardinality(Cardinality.SET).make() #加上.cardinality(Cardinality.SET)表示names的类型有String变为Set吗?
mgmt.buildIndex("search", Vertex.class).addKey(nameProperty, Mapping.STRING.asParameter()).buildMixedIndex("search")
mgmt.commit()
//Insert a vertex
person = graph.addVertex()
person.property("names", "Robert")
person.property("names", "Bob")
graph.tx().commit()
//Now query it
g.V().has("names", "Bob").count().next() //1
g.V().has("names", "Robert").count().next() //1
参考
官网. https://docs.janusgraph.org/latest/indexes.html
JanusGraph·Index中文笔记. https://blog.csdn.net/wzwdcld/article/details/81282431Indexing for Better Performance 使用索引加速性能
JanusGraph supports two different kinds of indexing to speed up query processing: graph indexes and vertex-centric indexes.
Graph Index
The name of a graph index must be unique.
//建索引语句,提供索引名称、被索引的元素类型(Vertex.class、Edge.class)
JanusGraphManagement.buildIndex(String:indexName, Class:className)
force-index =true
这不是表示必须要使用索引吗? 不是“”“不然就不会使用索引”的意思吧
Composite Index
Composite indexes are very fast and efficient but limited to equality lookups for a particular, previously-defined combination of property keys.
Mixed Index
Mixed indexes can be used for lookups on any combination of indexed keys and support multiple condition predicates in addition to equality depending on the backing index store.
g.V().has("name", "hercules")
// 2) Find all vertices with an age greater than 50
g.V().has("age", gt(50))
// or find all vertices between 1000 (inclusive) and 5000 (exclusive) years of age and order by increasing age
g.V().has("age", inside(1000, 5000)).order().by("age", incr)
// which returns the same result set as the following query but in reverse order
g.V().has("age", inside(1000, 5000)).order().by("age", decr)
// 3) Find all edges where the place is at most 50 kilometers from the given latitude-longitude pair
g.E().has("place", geoWithin(Geoshape.circle(37.97, 23.72, 50)))
// 4) Find all edges where reason contains the word "loves"
g.E().has("reason", textContains("loves"))
// or all edges which contain two words (need to chunk into individual words)
g.E().has("reason", textContains("loves")).has("reason", textContains("breezes"))
// or all edges which contain words that start with "lov"
g.E().has("reason", textContainsPrefix("lov"))
// or all edges which contain words that match the regular expression "br[ez]*s" in their entirety
g.E().has("reason", textContainsRegex("br[ez]*s"))
// or all edges which contain words similar to "love"
g.E().has("reason", textContainsFuzzy("love"))
// 5) Find all vertices older than a thousand years and named "saturn"
g.V().has("age", gt(1000)).has("name", "saturn")
Java端的代码,略有不同,参见:
GraphTraversalSource g = graph.traversal();
LinkedList times = new LinkedList();
long time;
Instant inst1;
Instant inst2;
//Query 1
inst1 = Instant.now();
List ret1 = g.V().has("type_object_type", "geography_mountain").toList();
inst2 = Instant.now();
time = Duration.between(inst1, inst2).toMillis();
times.add(time);
System.out.println("Query 1 used " + time + " ms. And query1 returns " + ret1.size() + " records.");
//Query 2
inst1 = Instant.now();
List ret2 = g.V().has("type_object_name", "\"美国\"").toList();
System.out.println("美国的records为" + ret2.size());
inst2 = Instant.now();
time = Duration.between(inst1, inst2).toMillis();
times.add(time);
System.out.println("Query 2 used " + time + " ms. And query2 returns " + ret2.size() + " records.");
//Query 3
inst1 = Instant.now();
List ret3 = g.V().has("type_object_type", "geography_mountain")
.has("geography_mountain_elevation", P.gt(1000)).toList();
inst2 = Instant.now();
time = Duration.between(inst1, inst2).toMillis();
times.add(time);
System.out.println("Query 3 used " + time + " ms. And query3 returns " + ret3.size() + " records.");
//Query 4
inst1 = Instant.now();
List