请帮帮我。
如何为这些数据制定最佳的文档方案?
每个城市的产品数量都有数据:

  • product1, [city = city1, available = 0], [city = city2, available = 2], [city = city3, available = 1], ...
    ...
  • product100, [city = city1, available = 1], [city = city2, available = 1], [city = city3, available = 1], ...

  • 如果产品可以是 1000 个,城市可以是 100 个并且城市可用搜索有效,那么如何为每个产品保存这些数据?

    最佳答案

    我会按如下方式存储它们:

    {
      "product" : "product1",
      "city-avail" : [
          {
            "city" : "city1",
            "available" : 0
          },
          {
            "city" : "city2",
            "available" : 1
          }
        ]
    }
    {
      "product" : "product2",
      "city-avail" : [
          {
            "city" : "city3",
            "available" : 1
          },
          {
            "city" : "city2",
            "available" : 0
          }
        ]
    }
    

    关于Elasticsearch - 如何存储数据,嵌套还是数组?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46088233/

    10-10 17:57