dynamoid
dynamoid copied to clipboard
how to update already existing global secondary index with new projected attributes
I created a table called student in dynamodb with fields name, email, mobile_number and school_id and added those 3 fields to global secondary index Ex: global_secondary_index :hash_key => :school_id, :projected_attributes => [:name, :email, :mobile_number], :projected_type => :include
Now i added new field in student table called address and i added it in global secondary index as Ex: global_secondary_index :hash_key => :school_id, :projected_attributes => [:name, :email, :mobile_number, :address], :projected_type => :include
I tried to retrieve students using global secondary index, the address field is nil in all student rows(result). can we update global secondary index with new field values ? or any thing like reindex ?
Did you recreate the index afterward?
Changing the projected_attributes
in the model will not affect the existing index. In this case if you created the table based on the original parameters then your table will have only included the initial set of projected fields, i.e. [:name, :email, :mobile_number]
.
If you want to update to include :address
, you'll need to recreate the Global Secondary Index with the new set of projected fields so DynamoDB knows to include that attribute in the index.
You can do this in AWS console if you delete the index and create it again with the appropriate fields for the Projected Attributes. If you feel like the fields may change more then I'd suggest just having it project all fields rather than including the specific ones (though you should still consider the space requirements you may have if you have a lot of fields).
So there is no such thing like update indexing. We need to delete index and re create again. Thank you @richardhsu .
@pboling Should we start a wiki or add a FAQ to the README? Seems like this sort of question was in few issues questions so might be worthwhile to address in a global way. Also maybe close this issue?
@philipmw is the only admin on the project, and is no longer active. I think a community wiki is a great idea.