DynamoDB 查询 JSON 对象的子字段

DynamoDB query on sub field of JSON Object(DynamoDB 查询 JSON 对象的子字段)

本文介绍了DynamoDB 查询 JSON 对象的子字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在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 对象的子字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:DynamoDB 查询 JSON 对象的子字段

基础教程推荐