A newer version of this documentation is available.

View Latest

Query String Queries

      +
      Query strings enable humans to describe complex queries using a simple syntax.

      Using the query string syntax, the following query types can be performed:

      Match

      A term without any other syntax is interpreted as a match query for the term in the default field. The default field is _all.

      For example, pool performs a match query for the term pool.

      Match Phrases

      Placing the search terms in quotes performs a match phrase query.

      For example, "continental breakfast" performs a match phrase query for the phrase continental breakfast.

      Field Scoping

      You can specify the field in which to search by prefixing the term with a field-name, separated by a colon.

      The field-name may be a path to a field, using dot notation. The path must use Search syntax rather than N1QL syntax; in other words, you cannot specify array locations such as [*] or [3] in the path.

      For example, description:pool performs a match query for the term pool, in the description field.

      Required, Optional, and Exclusion

      When a query string includes multiple items, by default these are placed into the SHOULD clause of a boolean query. You can adjust this by prefixing items with + or -.

      • Prefixing with + places that item in the MUST portion of the boolean query.

      • Prefixing with - places that item in the MUST NOT portion of the boolean query.

      For example, +description:pool -continental breakfast performs a boolean query that MUST satisfy the match query for the term pool in the description field, MUST NOT satisfy the match query for the term continental in the default field, and SHOULD satisfy the match query for the term breakfast in the default field. Result documents satisfying the SHOULD clause score higher than those that do not.

      Boosting

      When multiple query-clauses are specified, you can specify the relative importance a given clause by suffixing it with the ^ operator, followed by a number.

      For example, description:pool name:pool^5 performs Match Queries for pool in both the name and description fields, but documents having the term in the name field score higher.

      Numeric Ranges

      You can specify numeric ranges with the >, >=, <, and <= operators, each followed by a numeric value.

      For example, reviews.ratings.Cleanliness:>4 performs a numeric range query on the reviews.ratings.Cleanliness field, for values greater than 4.

      Date Ranges

      You can perform date range searches by using the >, >=, <, and <= operators, followed by a date value in quotes.

      For example, created:>"2016-09-21" will perform a date range query on the created field for values after September 21, 2016.

      Escaping

      The following quoted string enumerates the characters which may be escaped:

      "+-=&|><!(){}[]^\"~*?:\\/ "
      This list contains the space character.

      In order to escape these characters, they are prefixed with the \ (backslash) character. In all cases, using the escaped version produces the character itself and is not interpreted by the lexer.

      For example:

      • my\ name is interpreted as a single argument to a match query with the value "my name".

      • "contains a\" character" is interpreted as a single argument to a phrase query with the value contains a " character.