【问题标题】:How to create an index over an property which is a list of objects in OrientDB?如何在作为 OrientDB 中对象列表的属性上创建索引?
【发布时间】:2015-01-13 08:31:48
【问题描述】:

我想要一个存储这样结构的类:

{
  name: "blabla",
  metaData: [ {a: "mya"}, { a:"mya2"} ]  
}

`

现在,我想在 metaData[?].a 字段上创建一个索引

  1. 在架构中表示此元数据的最佳方式是什么?作为一个嵌入式列表?
  2. 是否有可能拥有我想要的索引?
  3. 如果是这样,通过“a”值检索实体的查询应该是什么样的?
  4. 或者,如果我们有一个名为“myAs”的字段而不是那个元数据,它是一个 简单的字符串数组 - 会更容易吗?

请注意,我使用的是Node.JS oriento 库。

【问题讨论】:

    标签: javascript node.js orientdb oriento


    【解决方案1】:

    我不知道你想要的索引是否可能,但是如果你按照你在第4点说的做,是可以定义索引的(我定义为unique,但其他人会工作)。

    你可以:

    create class Test
    create property Test.name string
    create property Test.metaData embeddedlist string
    
    insert into Test set name = 'blabla', metaData = ['mya', 'mya2']
    
    CREATE INDEX Test.metaData UNIQUE
    
    insert into Test set metaData = ['mya', 'mya2'] # this will throw an exception
    

    您在第 3 点中提出的查询可能类似于:

    select from Test where 'mya' in metaData
    

    更新

    您还可以索引嵌入的地图。 (见here

    create property Test.metaDataTwo embeddedmap string
    create index myIndex on Test (metaDataTwo by value) unique
    
    insert into Test set name = 'blabla', metaDataTwo = {'prop1':'value1', 'prop2':'value2'}
    insert into Test set metaDataTwo = {'prop3':'value1'}  # this will throw an exception
    

    使用此类索引的查询应该是:

    select from Test where ( metaDataTwo containskey 'prop1' ) and (  metaDataTwo['prop1'] = 'value1' )
    

    【讨论】:

    • 假设将使用一个数组,是的,这就是查询。一个仍然悬而未决的问题:是否会被索引,这意味着每个数组项都有一个索引条目(mongodb 会这样做)。
    • 我认为它索引了整个列表。
    • 看到 OrientDB 不支持在复杂数据结构中建立索引。见this issue
    猜你喜欢
    • 2016-11-27
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 2012-03-13
    • 2014-10-17
    • 1970-01-01
    • 2015-12-16
    • 2012-06-10
    相关资源
    最近更新 更多