問題描述
是否可以在dynamoDB表中搜索json對象的子字段?
Is it possible to search for a subfield of a json object in dynamoDB table?
我的桌子:
Item: "item name",
Location: {...},
ItemInformation :
{
ItemName: "itemName",
ProductLine: {
Brand: "Razer",
ManufacturerSource: "Razer"
}
原來在這個表中ItemInformation是一個key,搜索一個對象,我們會為item信息構造json,然后用json字符串作為key進行查詢.現在我們需要實現按該對象的子字段搜索,每次可以包含不同的字段,即isDigital: "true".
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".
我在問題中注意到:DynamoDB 高級掃描 - JAVA
答案似乎是否定的,我必須將字段分開.但我很好奇 PHP 庫為什么以及如何在 dynamoDB 中查詢 JSON 對象上的子字段.真的沒有更好的解決方案,然后將列存儲為單獨的字段,然后在所有字段上添加索引?
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?
推薦答案
查看文檔后,按照我最初的意圖實現搜索字段是不可行的.問題是,雖然值是 JSON,但它們存儲為字符串文字,所以我必須進行重構才能開始存儲為 JSON 對象.此外,我無法添加列和索引,因為搜索可以對任意數量的字段進行操作,并且不同的項目可以有不同的字段,即項目可以有品牌、電池信息、名稱.鑒于要求是這些子字段中的任何一個都應該是可搜索的,因此最好在 Cloud Search 或 ElasticSearch 中執行此操作,我可以在對象的列中對任意字段和值進行索引和搜索.
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.
由于這是一個 DynamoDB 表,我將使用 CloudSearch,因為它提供了更簡單的索引選項和數據集成.
Since this is a DynamoDB table, I am going to use CloudSearch since it offers easier indexing option and integration for data.
這篇關于DynamoDB 查詢 JSON 對象的子字段的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!