【问题标题】:Arangodb dynamic index on object keys对象键上的 Arangodb 动态索引
【发布时间】:2016-01-08 21:18:27
【问题描述】:

Arangodb 2.8b3

有一些属性“规范”的文档,里面可以有 1-100 个键,比如

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

通过specification.key快速查询任务

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

尝试使用以下字段创建哈希索引:“specification”、“specification.*”、specification[*]、specification[*].*

从未使用过索引,是否存在无需重组结构或未来计划的解决方案?

【问题讨论】:

    标签: indexing arangodb aql


    【解决方案1】:

    不,我们目前不知道如何处理此类结构的索引。内存使用量也会增加,因为属性名称也必须出现在每个索引值的索引中。

    我们将发布什么with 2.8 is the ability to use indices on array structures

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

    文件如下:

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

    像这样使用 AQL 查询:

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

    您还可以在数组下索引文档:

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

    以下查询将使用数组索引:

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

    但是,星号只能用于数组访问 - 它不能替换对象中的键匹配。

    【讨论】:

    • 最后一个变体没有解决,我搜索的不是值,我需要将值与键(键 = A 和值 = B)进行比较,而不是值中的值。 Elasticsearch 有对象的动态映射索引,现在我用它来查找,然后通过 ids 从 arangodb 中选择记录。听起来很奇怪,但它更快..
    猜你喜欢
    • 2018-04-14
    • 1970-01-01
    • 2021-06-13
    • 1970-01-01
    • 1970-01-01
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    相关资源
    最近更新 更多