数据建模 – Aerospike数据建模和查询

可以说我在JAVA中有以下模型

class Shape {
    String type;
    String color;
    String size;
}

并说我有以下基于上述模型的数据.

Triangle,Blue,Small
Triangle,Red,Large
Circle,Small
Circle,Medium
Square,Green,Medium
Star,Large

我想回答以下问题

Given the type Circle how many unique colors?
    Answer: 1
Given the type Circle how many unique sizes?
    Answer: 2

Given the color Blue how many unique shapes?
    Answer: 2
Given the color Blue how many unique sizes?
    Answer: 3

Given the size Small how many unique shapes?
    Answer: 2
Given the size Small how many unique colors?
    Answer: 1

我想知道我是否应该按照以下方式进行建模……

set: shapes -> key: type -> bin(s): list of colors,list of sizes
set: colors -> key: color -> bin(s): list of shapes,list of sizes
set: sizes -> key: size -> bin(s): list of shapes,list of colors

或者有更好的方法吗?如果我这样做,我需要3倍的存储空间.

我还希望每套都有数十亿条目.顺便说一下模型已被编辑以保护inoncent代码;)

解决方法

NoSQL中的数据建模总是关于您计划如何检索数据,吞吐量和延迟.

有几种方法可以对这些数据进行建模;最简单的是模仿每个字段变为Bin的类结构.您可以在每个bin上定义Secondary Indexes并使用Aggregation Queries来回答您的问题(上图).

但这只是一种方式;您可能需要使用不同的数据模型来满足延迟和吞吐量的因素.

相关文章

文章浏览阅读752次。关系型数据库关系型数据库是一个结构化的...
文章浏览阅读687次,点赞2次,收藏5次。商城系统中,抢购和秒...
文章浏览阅读1.4k次。MongoTemplate开发spring-data-mongodb...
文章浏览阅读887次,点赞10次,收藏19次。1.背景介绍1. 背景...
文章浏览阅读819次。MongoDB连接失败记录_edentialmechanisn...
文章浏览阅读470次。mongodb抽取数据到ES,使用ELK内部插件无...