RethinkDB:​​在嵌套数组中创建索引(运行到大数据场景)

hag*_*ggy 2 rethinkdb

这是一个示例文档:

{
    "id": 12345,
    "links": [
        {
            url: "http://something.com",
            created: 1234567890987
        },
        {
            url: "http://somethingelse.com",
            created: 1234567891548
        },
        {
            url: "http://somethingweird.com",
            created: 1234567898555
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

created字段只是一个unix时间戳.我希望能够createdlinks数组的每个项目中包含的字段上运行索引查询.我不知道如何去做(或者如果可能的话).例如,由于表中有大量文档(大约7百万),因此该查询甚至无法完成:

r.db('test').table('very_large_table')
  .filter(function(row) {
    return row('links').filter(function(link) {
        return link('created').ge(1425293715379) 
    }).isEmpty().not()
  })
  .count()
Run Code Online (Sandbox Code Playgroud)

编辑由于数据集太大,我放弃了聚合策略的实时查询.现在,我们没有尝试按要求查询此数据,而是使用消息队列和数据聚合作业来压缩这些数据,因此它已经处理并且查询速度超快.再次感谢您的帮助!

Atn*_*nNn 6

您可以在以下created字段上创建多索引:

r.db('test').table('very_large_table')
 .indexCreate('links_created', r.row('links')('created'), {multi:true})
Run Code Online (Sandbox Code Playgroud)

并使用这样的索引:

r.db('test').table('very_large_table')
 .between(1425293715379, null, {index:'links_created'})
Run Code Online (Sandbox Code Playgroud)

请参阅此处的文档:http://rethinkdb.com/docs/secondary-indexes/python/