The query clause is a required part of every search request. It specifies what to search for and which index field to search in. Combine multiple conditions using logical operators to build complex queries.
For example, you can combine the title and subject fields of the TEXT type to create the composite index field default. Then, you can perform searches based on the index field default to retrieve the documents where the title or subject field contains the search query.
You can also use only the title field to create the index field title_search. Then, when you perform searches based on the index field title_search, only the documents where the title field contains the search query can be retrieved.
Syntax
A query clause takes one of the following forms:
| Query type | Syntax |
|---|---|
| Keyword search | index:'<search query>' ^ boost |
| Geographic range search | index:'circle (<longitude>, <latitude>, <radius>)' |
| Numeric range search | index:[<value1>, <value2>] |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
index | String | Yes | The index field to search. Configured when you define the index schema. |
search query | String | Yes | The term or phrase to search for. Enclose in single quotation marks (') or double quotation marks (""). |
boost | INT | No | Relevance weight for the query condition. Valid values: 0–99. Default: 99. Values below 0 are treated as 0; values above 99 are treated as 99. Takes effect only when exact_match_boost() is configured in a rough sort expression. |
Logical operators
Combine multiple query conditions using the following operators. All operators must be uppercase.
| Operator | Logic | Priority (lowest to highest) | Example |
|---|---|---|---|
RANK | Documents matching the second condition are ranked higher | 1 (lowest) | title:'cloud' RANK title:'search' |
OR | Either condition must match | 2 | title:'cloud' OR title:'search' |
AND | Both conditions must match | 3 | title:'cloud' AND type:'1' |
ANDNOT | First condition matches; documents matching the second are excluded | 4 | title:'cloud' ANDNOT title:'storage' |
() | Grouping — evaluated first | 5 (highest) | (title:'a' OR title:'b') AND type:'1' |
The | character is an alternate form of OR:
query=title:'Peking University'|'Zhejiang University'Phrase queries
Enclose a search query in double quotation marks to perform a phrase query. In a phrase query, all the terms are connected and arranged in the same order before and after analysis.
query=title:"Peking University"This returns only documents where the title contains "Peking University" as a phrase. Documents containing "University in Beijing" are not returned.
Examples
Search by a single field
query=title:'Peking University'AND: both conditions must match
query=title:'Peking University' AND title:'Zhejiang University'OR with AND: mixed conditions
query=(title:'Peking University' OR title:'Zhejiang University') AND type:'1'ANDNOT with RANK: exclude and boost
query=(title:'Peking University' ANDNOT title:'Tsinghua') RANK title:'Principal'
// Fine sort expression: text_relevance(title)Documents whose title contains "Peking University" but not "Tsinghua" are returned. Among them, documents whose title also contains "Principal" are ranked higher.
Search an ARRAY type index field
// arr_index_1 is an index built on an INT ARR field.
// Returns documents where arr_index_1 contains the value 1.
query=arr_index_1:'1'Usage notes
The query clause is required and cannot be empty.
Search queries must be enclosed in single quotation marks (
') or double quotation marks (""). A missing quotation mark causes a query error or unexpected results.Only
TEXTandSHORT_TEXTfields can be combined to create a composite index.For how terms are analyzed and tokenized, see Built-in analyzer.
For geographic and numeric range queries, see Range search.