Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indexing on nested field

I'm trying to create an index on a nested field, using the Dashboard in AWS Developer Console. E.g. if I have the following schema:

{ 'id': 1,
  'nested': {
     'mode': 'mode1',
     'text': 'nice text' 
  }
}

I was able to create the index on nested.mode, but whenever I then go to query by index, nothing ever comes back. It makes me think that DynamoDB created the index on a field name nested.mode instead of the mode field of nested. Any hints re. what I might be doing wrong?

like image 925
Cosmin SD Avatar asked May 25 '15 13:05

Cosmin SD


People also ask

What is nested index?

The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way that they can be queried independently of each other.

How do I index a field in MongoDB?

MongoDB provides complete support for indexes on any field in a collection of documents. By default, all collections have an index on the _id field, and applications and users may add additional indexes to support important queries and operations. This document describes ascending/descending indexes on a single field.

Can you create an index on an array field in MongoDB?

To index a field that holds an array value, MongoDB creates an index key for each element in the array. These multikey indexes support efficient queries against array fields. Multikey indexes can be constructed over arrays that hold both scalar values [1] (e.g. strings, numbers) and nested documents.


1 Answers

You cannot (currently) create a secondary index off of a nested attribute. From the Improving Data Access with Secondary Indexes in DynamoDB documentation (emphasis mine):

For each secondary index, you must specify the following:

...

  • The key schema for the index. Every attribute in the index key schema must be a top-level attribute of type String, Number, or Binary. Nested attributes and multi-valued sets are not allowed. Other requirements for the key schema depend on the type of index:

You can, however, create an index on any top level JSON element.

like image 55
mkobit Avatar answered Sep 27 '22 18:09

mkobit