0

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

Alexander Patrikalakis
  • 5,054
  • 1
  • 30
  • 48
anjnkmr
  • 838
  • 15
  • 37
  • 1
    DynamoDB doesn't support querying the HashKey for a partial match like this. You probably need to look into indexing your data in something like Elasticsearch. – Mark B Jan 05 '17 at 15:04
  • Thanks & i have a doubt, is that data permanent & can i store some aggregate data in Elastic Search – anjnkmr Jan 06 '17 at 04:03
  • @MarkB can you please check this answer http://stackoverflow.com/a/41513677/4234949 – anjnkmr Jan 10 '17 at 03:44

2 Answers2

2

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.

Bruno Buccolo
  • 1,111
  • 9
  • 20
  • But `scan` operation scans `whole table` if the table has more rows it is very difficult do `scan` operation each time user searching, so i'm going to use elastic search as @MarkB suggested, If i'm wrong, can you please explain more thanks – anjnkmr Jan 07 '17 at 04:38
  • You're correct, `scan` goes through the whole table. However, if this is only the list of all countries in the world, you should be fine. You should also note that there is a replication lag from `Dynamo` to `ElasticSearch`. If as soon as you insert an item on `Dynamo` you query `ElasticSearch` it might not be there. Again, if this is a list of all countries, you should be fine too because countries don't change that often. – Bruno Buccolo Jan 07 '17 at 15:06
  • It is not a static list, the list will be updated as users starts using the application, so i tried to use eastic search, and i manually added the items to index in elastic search when an new item inserted, and it working fine now. Can you please explain more about the replication lag - i can't find any way to set replication to dynamodb and elastic search, how can i setup the replication for dynamodb and elastic search – anjnkmr Jan 10 '17 at 03:43
0

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

anjnkmr
  • 838
  • 15
  • 37