Amazon dynamodb 如何将数据格式化为algolia

Amazon dynamodb 如何将数据格式化为algolia,amazon-dynamodb,algolia,Amazon Dynamodb,Algolia,我正在学习如何使用Algolia,我有几个问题 我有一个table FreightDriver,它与table Truck有一对多的关系 id: ID! name: String! email: String! phoneNumber: String! cities: [String!]! state: String! country: String! picture: String trucks: [Truck] @connection(keyName: "byFreightDriv

我正在学习如何使用Algolia,我有几个问题

我有一个table FreightDriver,它与table Truck有一对多的关系

id: ID!
name: String!
email: String!
phoneNumber: String!
cities: [String!]!
state: String!
country: String!
picture: String
trucks: [Truck] @connection(keyName: "byFreightDriver", fields: ["id"])
然后,桌上卡车,它与桌上货车司机有一对一的关系,还有另一个桌,也是Box
一对一的关系

id: ID!
freightDriverId: ID!
boxId: ID!
brand: String!
model: String!
yearModel: Int!
// and more fields
freightDriver: FreightDriver @connection(fields: ["freightDriverId"])
box: Box @connection(fields: ["boxId"])
和桌上的盒子:

id: ID!
type: String!
width: Float!
height: Float!
depth: Float!
我想根据货运司机所在的州和城市来查找卡车,并且(如果用户需要的话)根据箱子类型和卡车的品牌或型号来查找(作为示例)

按州和城市查找货运司机的示例:

{
  "data": {
    "freightDriversByState": {
      "items": [
        {
          "name": "Andrés Montoya",
          "cities": [
            "GUADALAJARA"
          ],
          "state": "JALISCO",
          "country": "MX",
          "trucks": {
            "items": [
              {
                "brand": "chevrolet",
                "model": "12",
                "yearModel": 2020,
                "box": {
                  "type": "Ganadera",
                  "width": 1,
                  "height": 2,
                  "depth": 3
                }
              },
              {
                "brand": "chevrolet",
                "model": "12",
                "yearModel": 2020,
                "box": {
                  "type": "Seca (abierta)",
                  "width": 12,
                  "height": 12,
                  "depth": 12
                }
              },
              {
                "brand": "chevrolet",
                "model": "12",
                "yearModel": 2020,
                "box": {
                  "type": "Seca (abierta)",
                  "width": 12,
                  "height": 12,
                  "depth": 12
                }
              },
              {
                "brand": "chevrolet",
                "model": "Semi",
                "yearModel": 2020,
                "box": {
                  "type": "Seca (abierta)",
                  "width": 1,
                  "height": 2,
                  "depth": 3
                }
              },
              {
                "brand": "chevrolet",
                "model": "12",
                "yearModel": 2020,
                "box": {
                  "type": "Seca (abierta)",
                  "width": 1,
                  "height": 2,
                  "depth": 3
                }
              },
              {
                "brand": "chevrolet",
                "model": "12",
                "yearModel": 2020,
                "box": {
                  "type": "Volcadora",
                  "width": 1,
                  "height": 2,
                  "depth": 3
                }
              },
              {
                "brand": "hola",
                "model": "12",
                "yearModel": 12,
                "box": {
                  "type": "Plataforma",
                  "width": 1,
                  "height": 2,
                  "depth": 3
                }
              },
              {
                "brand": "Ford",
                "model": "12",
                "yearModel": 2020,
                "box": {
                  "type": "Seca (abierta)",
                  "width": 1,
                  "height": 2,
                  "depth": 1
                }
              },
              {
                "brand": "dasdas",
                "model": "12",
                "yearModel": 12231,
                "box": {
                  "type": "Grúa",
                  "width": 1,
                  "height": 2,
                  "depth": 3
                }
              },
              {
                "brand": "Tesla",
                "model": "Semi",
                "yearModel": 2020,
                "box": {
                  "type": "Seca (abierta)",
                  "width": 4,
                  "height": 4,
                  "depth": 2
                }
              }
            ]
          }
        },
        {
          "name": "Roberto mendez",
          "cities": [
            "GUADALAJARA"
          ],
          "state": "JALISCO",
          "country": "MX",
          "trucks": {
            "items": []
          }
        },
        {
          "name": "Fletes Jalisco Sa de Cv ",
          "cities": [
            "GUADALAJARA"
          ],
          "state": "JALISCO",
          "country": "MX",
          "trucks": {
            "items": [
              {
                "brand": "Ford",
                "model": "F-450",
                "yearModel": 2018,
                "box": {
                  "type": "Seca (cerrada)",
                  "width": 2.7,
                  "height": 2.5,
                  "depth": 4.5
                }
              },
              {
                "brand": "Hiundai",
                "model": "H100",
                "yearModel": 2009,
                "box": {
                  "type": "Seca (abierta)",
                  "width": 2.3,
                  "height": 2,
                  "depth": 4
                }
              },
              {
                "brand": "Hiundai",
                "model": "H100",
                "yearModel": 2020,
                "box": {
                  "type": "Seca (abierta)",
                  "width": 2.35,
                  "height": 2,
                  "depth": 3
                }
              },
              {
                "brand": "Ford",
                "model": "F-450",
                "yearModel": 2018,
                "box": {
                  "type": "Seca (cerrada)",
                  "width": 2.7,
                  "height": 2.2,
                  "depth": 3
                }
              },
              {
                "brand": "Ford",
                "model": "F-450",
                "yearModel": 2004,
                "box": {
                  "type": "Seca (abierta)",
                  "width": 2.5,
                  "height": 2,
                  "depth": 3
                }
              }
            ]
          }
        },
        {
          "name": "Cotransport",
          "cities": [
            "GUADALAJARA"
          ],
          "state": "JALISCO",
          "country": "MX",
          "trucks": {
            "items": [
              {
                "brand": "Chevrolet",
                "model": "CX-5",
                "yearModel": 2019,
                "box": {
                  "type": "Seca (cerrada)",
                  "width": 4,
                  "height": 3,
                  "depth": 4
                }
              }
            ]
          }
        },
        {
          "name": "Andrés",
          "cities": [
            "EL LIMÓN",
            "MAGDALENA",
            "SANTA MARÍA DEL ORO",
            "GUADALAJARA",
            "ETZATLÁN"
          ],
          "state": "JALISCO",
          "country": "MX",
          "trucks": {
            "items": [
              {
                "brand": "chevrolet",
                "model": "12",
                "yearModel": 2020,
                "box": {
                  "type": "Seca (abierta)",
                  "width": 1,
                  "height": 2,
                  "depth": 3
                }
              }
            ]
          }
        }
      ]
    }
  }
}

但是,如果我想使用货运司机所在的州和城市、箱子的类型以及卡车的型号或品牌,这就是问题所在,因为我使用的是Dynamodb,而这一个没有关系,因此,获取准确数据有点棘手。这就是我想使用Algolia的原因,但是在这种情况下,如何格式化Algolia的数据呢?我需要做什么?谢谢

如果有人感兴趣,下面是答案