couchdb - Querying on map key/value pair in couch db -
i've been reading on documentation couch db views (http://wiki.apache.org/couchdb/http_view_api#http_view_api, http://www.barkingiguana.com/2009/01/22/filtering-and-ordering-couchdb-view-results/) i'm not finding i'm looking , i'm beginning think not supported.
i have 2 records in couch database
{ "_id": "uuid", "_rev": "rev", "status": "complete", "csv": [ { "lower": 0.09, "upper": 0.31 } ], "tags": { "get_info": { "duration": "24", "location": "south" } } }
and
{ "_id": "2-uuid", "_rev": "2-rev", "status": "complete", "csv": [ { "lower": 0.01, "upper": 0.70 } ], "tags": { "different_info": { "duration": "60", "location": "south" } } }
is possible create view , add query parameters return records have tag "key":"value" (e.g want records tagged "duration":24 or want records tagged "location":"south"). don't want hard code key/values view - should passed query.
is there way of thinking that's not view?
one way accomplish emit tags in view array using [ key, value ]
:
function (doc) { (var type in doc.tags) { (var tag in doc.tags[type]) { emit([ tag, doc.tags[type][tag] ]); } } }
you can query view specific pair: key=["duration","24"]
. can ranged searches startkey
, endkey
.
you can specify list of keys if opt post
instead: keys[]=["duration","24"]&keys[]=["location","south"]
. however, method lose ability ranged searches. (at least atm)
when querying multiple keys this, you'll getting documents match of keys, may need deduplicate results on client side.
couchdb views more computation , algorithms, , not best arbitrary queries , searching. that, highly recommend adding search layer, such couchdb-lucene or elasticsearch.
Comments
Post a Comment