Full Text Queries

Full-text queries search the cluster for documents matching certain terms or strings of texts. Unlike N1QL queries which are designed to be structured, i.e. ensuring that a given document field matches a given value, full-text queries are more free-form, allowing the ability to search multiple fields and to add variance in queries.

Couchbase offers full-text queries in version 4.5. To issue a query from the Python SDK, use the search() cluster method.

To perform an actual search, define a search index (via Couchbase web UI, or using the REST interface), create a Query object and then pass the index name and the query object to the search method:

query = ConjunctionQuery(TermQuery("couchbase"), MatchQuery("nosql"))
for hit in cluster.search('indexName', query):
    print(hit)

The above query searches for any document which has both nosql and couchbase in any of its fields. Note that PhraseQuery may be better suited for this kind of query

query = PhraseQuery('couchbase', 'nosql')
for hit in cluster.search('indexName', query):
    print(hit)

Query Types

You may issue simple match queries (MatchQuery) to inspect a user term; TermQuery to match a field exactly, PrefixQuery for type-ahead queries, or a compound query type such as ConjunctionQuery for more complex queries.

Match Queries

Range Queries

Compound Queries

Debugging Queries

Parameters

Query parameters may be passed as the options keyword argument to search().

Facets

Facets allow additional aggregate information to be returned in the results. You can count how many documents match specific criteria based on ranges and matches.