Skip to content

唯一索引查询问题,该如何定义才能查询ok #832

Closed

Description

@CPJ-data

代码如下:
HugeClient hugeClient = new HugeClient("http://127.0.0.1:8080", "hugegraph");
SchemaManager schema = hugeClient.schema();

    schema.propertyKey("weight").asDouble().ifNotExist().create();
    schema.propertyKey("name").asText().ifNotExist().create();
    schema.vertexLabel("user")
            .properties("name")
            .primaryKeys("name")
            .ifNotExist()
            .create();
    schema.edgeLabel("like")
            .sourceLabel("user")
            .targetLabel("user")
            .properties("weight")
            .ifNotExist()
            .create();
    schema.indexLabel("likeByWeight")
            .onE("like")
            .by("weight")
            .unique()
            .ifNotExist()
            .create();

    GraphManager graph = hugeClient.graph();
    Vertex marko = graph.addVertex(T.label, "user", "name", "marko");
    Vertex vadas = graph.addVertex(T.label, "user", "name", "vadas");
    marko.addEdge("like", vadas, "weight", 0.5);

    GremlinManager gremlin = hugeClient.gremlin();
    ResultSet execute = gremlin.gremlin("g.E().hasLabel(\"like\").has(\"weight\", 0.5)").execute();
    Object object = execute.iterator().next().getObject();
    System.out.println(((Edge)object).properties());
    hugeClient.close();

报错信息如下:
Exception in thread "main" java.lang.AssertionError: Unknown index type 'UNIQUE'
at com.baidu.hugegraph.exception.ServerException.fromResponse(ServerException.java:44)
at com.baidu.hugegraph.client.RestClient.checkStatus(RestClient.java:100)
at com.baidu.hugegraph.rest.RestClient.post(RestClient.java:156)
at com.baidu.hugegraph.rest.RestClient.post(RestClient.java:133)
at com.baidu.hugegraph.api.gremlin.GremlinAPI.post(GremlinAPI.java:41)
at com.baidu.hugegraph.driver.GremlinManager.execute(GremlinManager.java:51)
at com.baidu.hugegraph.api.gremlin.GremlinRequest$Builder.execute(GremlinRequest.java:55)
at huge.HugeGraph.main(HugeGraph.java:51)
Caused by: [java.lang.AssertionError]

各位大佬解答后能给个具体的代码吗?或者使用什么语法进行操作比较好,现在清楚的只有使用gremlin语法进行查询。

Activity

  1. javeme commented on Jan 15, 2020

    @javeme
    Contributor

    目前unique index不支持查询的,只能限制唯一约束,如果需要查询请再建立一个secondary index索引。

  2. CPJ-data commented on Jan 15, 2020

    @CPJ-data
    Author

    @javeme
    之前是通过写两个ID,赋值同样的值,一个建立唯一索引,一个建立查询索引进行操作
    之前提过该问题,说已经解决,重新进行测试结果如上。
    #795 [在ID建唯一索引,web界面用g.V().has("id","1223")查询报错]

  3. zhoney commented on Mar 4, 2020

    @zhoney
    Contributor

    @CPJ-data 你使用的server的版本是最新的master吗?这个unique index的问题已经fix,但是并没有cherry-pick到0.10.4的release版本中。如果需要请自行cherry-pick并重新打包server。更多细节可以参考 #795 的回复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions