简体   繁体   English

对象键上的Arangodb动态索引

[英]Arangodb dynamic index on object keys

Arangodb 2.8b3 阿兰戈卜2.8b3

Have document with some property "specification", can have 1-100 keys inside, like 具有具有某些属性“规范”的文档,里面可以有1-100个键,例如

document {
  ...
  specification: {
      key1: "value",
      ...
      key10: "value"
  }
}

Task fast query by specification.key 通过specification.key快速查询任务

For Doc IN MyCollection FILTER Doc.specification['key1'] == "value" RETURN Doc

Tried create hash indexes with field: "specification", "specification.*", specification[*], specification[*].* 尝试使用以下字段创建哈希索引:“规格”,“规格。*”,规格[*],规格[*]。*

Index never used, any solution without reorganizing structure or plans for future exists? 索引从未使用过,是否存在没有重组结构或未来计划的解决方案?

No, we currently don't have any smart idea how to handle indices for structures like that. 不,我们目前尚不知道如何处理类似结构的索引。 The memory usage would also increase since the attribute names would also have to be present in the index for each indexed value. 由于每个索引值的索引中还必须存在属性名称,因此内存使用量也会增加。

What we will release with 2.8 is the ability to use indices on array structures : 我们将在2.8中发布的功能是可以在数组结构上使用索引

db.posts.ensureIndex({ type: "hash", fields: [ "tags[*]" ] });

with documents like: 具有以下文件:

{ tags: [ "foobar", "bar", "anotherTag" ] }

Using AQL queries like this: 使用这样的AQL查询:

FOR doc IN posts
  FILTER 'foobar' IN doc.tags[*]
  RETURN doc

You could also index documents under arrays: 您还可以在数组下索引文档:

db.posts.ensureIndex({ type: "hash", fields: [ "tags[*].value" ] });
db.posts.insert({
  tags: [ { key: "key1", value: "foobar"},
          { key: "key2", value: "baz" },
          { key: "key3", value: "quux" }
        ] });

The following query will then use the array index: 然后,以下查询将使用数组索引:

FOR doc IN posts
  FILTER 'foobar' IN doc.tags[*].value
  RETURN doc

However, the asterisk can only be used for array accesses - it can't substitute key matches in objects. 但是,星号只能用于数组访问-不能替换对象中的键匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM