DynamoDB create index on map or list type

后端 未结 2 671
名媛妹妹
名媛妹妹 2020-12-15 02:58

I\'m trying to add an index to an attribute inside of a map object in DynamoDB and can\'t seem to find a way to do so. Is this something that is supported or are indexes rea

2条回答
  •  太阳男子
    2020-12-15 03:30

    I have tried doing hash(str(object)) while I store the object separately. This hash gives me an integer(Number) and I am able to use a secondary index on it. Below is a sample in python, it is important to use a hash function which generates the same hash key every time for the value. So I am using sha1.

    # Generate a small integer hash:
    import hashlib
    def hash_8_digits(source):
        return int(hashlib.sha1(source.encode()).hexdigest(), 16) % (10 ** 8)
    

    The idea is to keep the entire object small while still the entity intact. i.e. rather than serializing and storing the object as string and changing whole way the object is used I am storing a smaller hash value along with the actual list or map.

提交回复
热议问题