Reputation: 405
I have a document with several different attributes. In my app I want to do filtering on one of the doc attributes and possibility sorting by any of the other attribute.
i.e
{
"accountId": "qa32176148",
"id": "122230310111",
"rtSessionId": "qa321761484294973207",
"sessionStartTime": 1387705538426,
"visitorLastUpdateTime": 1387705717094,
"countryCode": "US",
"state": "NY",
"city": "New York",
"country": "United States",
"organization": "Google",
"ipAddress": "216.239.39.99",
"agentNickName": "john"
}
Upvotes: 1
Views: 390
Reputation: 2538
Basucally, yes, you need to create separate view for each attribute (in case, if you want filter only by one attribute). If you also need ability to filter results by two or more attributes in one query you will also need a view per each attribute combination. But I don't understand about what did you mean composite index
(may be if you saw some example, it would be greate if you show it). As I understand composite index it will not suite this situation at all.
Yes, in most cases. But you can do that only if you expect exact match on attribute X
, i.e. X == 1
(not range: X == 1 ... 6
). To sort by Y
attribute, just append it to your emit function after X
attribute:
emit([X,Y], null)
and use startKey
and endKey
params. I.e. startKey=[1]
, endkey=[1,{}]
.
Now I return to your first question. I think that case is used in some kind of search operation. So there is good couchbase extension for elasticsearch (also see this page), that will allow you much more flexebility in filtering and ordering without creating many views.
Upvotes: 1