Indexing on nested field

2020-02-06 05:29发布

问题:

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?

回答1:

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.