前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >JanusGraph实战笔记·数据写入·查询

JanusGraph实战笔记·数据写入·查询

作者头像
陈黎栋
发布2020-02-18 15:03:50
1.3K0
发布2020-02-18 15:03:50
举报
文章被收录于专栏:陈黎栋的专栏啦

Data Types·JanusGraph如何表示、写入和查询数组类型?

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:

JanusGraph·写入或导入数据·Load/Import/Write Data

以下Java函数中的codes在gremlin-server中当做

Collections(官方文档21.7)

If you are using Elasticsearch then you can index properties with SET and LIST cardinality(基数,不明白什意思). For instance:

代码语言:javascript
复制
mgmt = graph.openManagement()
nameProperty = mgmt.makePropertyKey("names").dataType(String.class).cardinality(Cardinality.SET).make() #加上.cardinality(Cardinality.SET)表示names的类型有String变为Set<String>吗?
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

Index

//建索引语句,提供索引名称、被索引的元素类型(Vertex.class、Edge.class) JanusGraphManagement.buildIndex(String:indexName, Class:className)

代码语言:txt
复制
- 配置文件中强制开启索引,不然就会不使用索引
-  force-index =true
代码语言:txt
复制
    -  这不是表示必须要使用索引吗? 不是“”“不然就不会使用索引”的意思吧
代码语言:txt
复制
-  Composite Index
代码语言:txt
复制
    -   Composite indexes are very fast and efficient but limited to equality lookups for a particular, previously-defined combination of property keys.
代码语言:txt
复制
-  Mixed Index
代码语言:txt
复制
    -  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.

query example

代码语言:javascript
复制
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端的代码,略有不同,参见:

代码语言:javascript
复制
  GraphTraversalSource g = graph.traversal();

        LinkedList<Long> times = new LinkedList<Long>();
        long time;
        Instant inst1;
        Instant inst2;

        //Query 1
        inst1 = Instant.now();
        List<Vertex> 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<Vertex> 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<Vertex> 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<Object> ret4 = g.V().has("type_object_type", "geography_mountain").order().values("type_object_name").toList();

        inst2 = Instant.now();
        time = Duration.between(inst1,inst2).toMillis();
        times.add(time);
        System.out.println("Query 4 used " + time + " ms. And query3 returns " + ret4.size() + " records.");

        //Query 5
        inst1 = Instant.now();
        List<Object> ret5 = g.V().has("name", "<http://knowledge.microsoft.com/5232ed96-85b1-2edb-12c6-63e6c597a1de>")
                .out("location_location_administrative_capital").has("type_object_alias").values("type_object_alias").toList();
        inst2 = Instant.now();
        time = Duration.between(inst1, inst2).toMillis();
        times.add(time);
        System.out.println("Query 5 used " + time + " ms. And query3 returns " + ret5.size() + " records.");

        //Query 6
        inst1 = Instant.now();
        List<Object> ret6 = g.V().has("type_object_type", "location_city").out("location_location_contained_by").
                out("location_location_contained_by").out("location_location_contained_by").
                values("location_location_area").limit(100)
                .toList();
        inst2 = Instant.now();
        time = Duration.between(inst1, inst2).toMillis();
        times.add(time);
        System.out.println("Query 6 used " + time + " ms. And query6 returns " + ret6.size() + " records.");


        return times;
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Data Types·JanusGraph如何表示、写入和查询数组类型?
  • JanusGraph·写入或导入数据·Load/Import/Write Data
    • Collections(官方文档21.7)
    • Index
    • query example
    相关产品与服务
    Elasticsearch Service
    腾讯云 Elasticsearch Service(ES)是云端全托管海量数据检索分析服务,拥有高性能自研内核,集成X-Pack。ES 支持通过自治索引、存算分离、集群巡检等特性轻松管理集群,也支持免运维、自动弹性、按需使用的 Serverless 模式。使用 ES 您可以高效构建信息检索、日志分析、运维监控等服务,它独特的向量检索还可助您构建基于语义、图像的AI深度应用。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档