0
votes

Is there any solution to search by multiple string keys in the Couchbase?

For example I have an index:

emit(['example', doc.field1, doc.field2], doc.id);

And field1 and field2 are string variables.

I cannot use startkey and endkey because compound array index key is still treated as a string. So I have problem like this. But also I have string keys. So I cannot use Spatial Views.

Is there any solution other than a finding of multiple result sets for each part of the key, and then finding their intersection?

1
Could you clarify what do you mean when you say: "cannot use startkey and endkey because compound array index key is still treated as a string"? - avsej
I mean partial Selection with Compound Keys (docs.couchbase.com/couchbase-manual-2.1/…): >> A limitation of this structure is that it is not possible to ignore the earlier array values. - poletaew

1 Answers

1
votes

If you are limited to using views, then as you already discovered, there is no way to filter by independent fields.

If you are using (or can upgrade to) Couchbase 4.x, then you can do this with a simple N1QL query:

SELECT * FROM bucket WHERE field1 = 'bla' AND field2 ='blabla'

Be sure to create indexes on the two fields:

CREATE INDEX ix_field1 ON bucket(field1)