2

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Last variant not solve, I search not value, I need compare value with key ( key = A and value = B) not value in values. Elasticsearch have dynamic mapping index for objects, now I use it for lookup, and then select records from arangodb by ids. As strange as it may sound, but it is faster ..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.