Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB query on sub field of JSON Object

Is it possible to search for a subfield of a json object in dynamoDB table?

My table:

Item: "item name",  
Location: {...},  
ItemInformation :  
{  
   ItemName: "itemName",  
   ProductLine: {  
      Brand: "Razer",  
      ManufacturerSource: "Razer"  
}

Originally in this table ItemInformation would be a key and searching for an object we would construct the json for the item information and then query with the json string as a key.. Now we need to implement searching by sub fields of that object, which can contain different fields each time, i.e. isDigital: "true".

I notice in the question: DynamoDB advanced scan - JAVA

The answer would seem to be no and I would have to separate out the fields. But I am curious about why and how the PHP library can query for sub fields on a JSON object in dynamoDB. Is there really no better solution then to store the column as separate fields and then add an index on all fields?

like image 298
Niru Avatar asked Jun 06 '16 23:06

Niru


1 Answers

After looking through documentation it is not feasible to implement the search fields as I originally intended. The problem is that while the values are JSON they are stored as string literals so I have to do refactoring to start storing as JSON objects. Additionally I cannot add in columns and index because the search could operate on any number of fields and different items can have different fields, i.e. an Item can have Brand, BatteryInformation, Name. Given that the requirement is that any of these subfields should be searchable its better to do this in Cloud Search or ElasticSearch where I can index and search on arbitrary fields and values within a column of an object.

Since this is a DynamoDB table, I am going to use CloudSearch since it offers easier indexing option and integration for data.

like image 164
Niru Avatar answered Oct 02 '22 08:10

Niru