简体   繁体   中英

Arangodb dynamic index on object keys

Arangodb 2.8b3

Have document with some property "specification", can have 1-100 keys inside, like

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

Task fast query by 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 :

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

with documents like:

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

Using AQL queries like this:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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