Similar to SQL LIKE statement in Couchbase

2019-02-28 23:22发布

问题:

Is this possible in Couchbase??

SELECT * FROM users WHERE user_name LIKE '%john%'.

Seems like I have to use startkey and endkey. But doesn't seem to get the right results.

回答1:

The startKey and endKey will allow you to do like "john%". Couchbase does not allow you to do a contains.

If you really need a contains you should use the Elastic Search plugin.



回答2:

Couchbase 4.5+ only


Is needed to create a Full Text Index to be able search for substrings.

  1. Log in to the Couchbase Web Console, for example, http://localhost:8091/.
  2. Click Indexes > Full Text, then click on the New Full Text Index button.
  3. A form where you can define your new index configuration is displayed.
  4. Each index needs a unique name. Type one in, such as"test-index". Only alphanumeric characters, hyphens, and underscores are allowed for index names. Also, the first character must be an alphabetic character. Choose a bucket from the drop-down list. There are more options, but you can ignore those for now and rely on the default values. Go! Finally, click the Create Index button.
  5. You should now see a summary page of your new full text index. The document count shows how many documents have been indexed so far. You can click on the Refresh button next to the Document Count field in order to see the indexing progress.

See Couchbase reference for more information


NOTE: If you don't see Full text tab, you have to enable it and setup Full Text Search service (Full Text RAM Quota).