多个键范围作为CouchDB视图的参数 [英] Multiple key ranges as parameters to a CouchDB view
问题描述
潜在的问题-假设我的文档包含类别 和时间戳。如果我想要 foo 类别中所有时间戳都在最近两个小时内的文档,则很简单:
函数(doc){
发出([doc.category,doc.timestamp],null);
}
,然后查询
获取服务器:5894 /.../ myview?startKey = [foo,| now-2 hours |]& endkey = [foo,| now |]
问题是当我想要类别 foo 或 bar ,在最近两个小时内。如果我不在乎时间,可以直接通过钥匙来拉动钥匙。不幸的是,我没有范围选项。
POST服务器:5894 /.../ myview
keys = [[foo,0 hours],[foo ,2 hours],[bar,0 hours],[bar,2 hours]]
它有效,但是如果我想返回大量时间(与块大小有关),将会变得混乱。
是否可以发送多个startKey / endKey对类似于键的视图:[]可以为键发布的数组?
有一个CouchDB问题请求让你做到这一点。我在票证上附加了一个简单的,无保证的补丁0.10.1,可能对您有用。它对我有用,让我做类似的事情:
{
keys:[
{
startkey:[ 0240286524, 2010, 03, 01],
endkey:[ 0240286524, 2010, 03, 07 ,{}]
},
{
startkey:[ 0442257276, 2010, 03, 01],
endkey:[ 0442257276, 2010, 03, 07,{}]
}
]
}
在POST正文中,这使我可以在多个日期范围内跨多个跟踪ID获取所有数据。我用 group = true& group_level = 1
打电话,将结果按跟踪ID分组。较深的组级别将允许我通过跟踪id | year,跟踪id | year | month等进行分组。
对于我来说,多个连接对我来说是无法扩展的开销希望同时达到2000:)(不,不能选择新视图-我们已经有400GB的数据和一个视图!)
问题和补丁在 https://issues.apache.org/jira/browse/COUCHDB-523。
The underlying problem - let's say my documents have "categories" and timestamps. If I want all documents in the "foo" category that have a timestamp that's within the last two hours, it's simple:
function (doc) {
emit([doc.category, doc.timestamp], null);
}
and then query as
GET server:5894/.../myview?startKey=[foo, |now - 2 hours|]&endkey=[foo, |now|]
the problem comes when I want something in categories foo or bar, within the last two hours. If I didn't care about time, I could just pull directly by key through the keys collection. unfortunately, I have no such option with ranges.
What I ended up doing in the meantime is rounding the timestamp to two-hour blocks, and then multiplexing the query out:
POST server:5894/.../myview
keys=[[foo, 0 hours], [foo, 2 hours], [bar, 0 hours], [bar, 2 hours]]
It works, but will get messy if I want to go back a large amount of time (in relationship to the blocksize).
Is there a way to send multiple startKey/endKey pairs to a view, akin to the keys: [] array that can be posted for keys?
There is a CouchDB issue request to let you do just that. I've attached a simple, no guarantees patch to 0.10.1 to that ticket which may work for you. It works for me and lets me do things like:
{
"keys": [
{
"startkey": ["0240286524","2010","03","01"],
"endkey": ["0240286524","2010","03","07",{}]
},
{
"startkey": ["0442257276","2010","03","01"],
"endkey": ["0442257276","2010","03","07",{}]
}
]
}
in the POST body, which lets me get all the data across multiple tracking ids, for a range of dates. I call with group=true&group_level=1
to have the results grouped by tracking id. Deeper group levels would allow me to group by tracking id|year, tracking id|year|month etc.
Multiple connections were an unscalable overhead for me as I'd be looking to make 2000 concurrently :) (No, a new view is not an option - we're already at 400GB for data plus one view!)
The issue and patch is at https://issues.apache.org/jira/browse/COUCHDB-523 .
这篇关于多个键范围作为CouchDB视图的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!