DynamoDB Search with HashKey

1k views Asked by At

I have table with the following structure

HashKey: Place Name
Attribute: Place Data Class

now i would like to search with Place Name,

Ex: I have below data

Newyork {lat: x.xxxxx, lng: x.xxxxxx} Newzealand {lat: x.xxxxx, lng: x.xxxxxx} IndialaPolis {lat: x.xxxxx, lng: x.xxxxxx}

when i searching with keyword new, it should return Newyork and Newzealand, I searched google for this, i found that we can get all records by the HashKey

2

There are 2 answers

0
anjnkmr On BEST ANSWER

Thank you @mark-b and @bruno-buccolo, as you said it is not possible to Search hashkey field

So i created Elastic Search Indexes for that table manually and updating each time the original record updates

3
Bruno Buccolo On

When doing a Query, you can only have exact matches on the HashKey.

However, there is also the Scan operation, that you can use along with a FilterExpression. Just note that Query and Scan perform and consume capacity differently. See the differences here.

Here are example parameters you could use on a Scan with begins_with:

{
    table_name: tableName,
    filter_expression: "begins_with(#country, :search)",
    expression_attribute_names: {
        "#country" => "country"
    },
    expression_attribute_values: {
        ":search" => "new" 
    }
}

This article is a good place to start.