Clause description
The query clause is a fundamental component of a search statement. It specifies what to search for in an index field and lets you define multiple search conditions and their relationships, such as AND, OR, ANDNOT, or RANK.
For example, you can combine two TEXT fields, such as `title` and `subject`, to create a common index named `default`. A query on the `default` index then retrieves documents where the search query matches the text in either the `title` or `subject` field.
If you create a separate index named `title_search` for the `title` field, a query on that index retrieves a document only if the search query matches the text in the `title` field.
Syntax
Simple queries
Syntax:
query=index_name:'search_query'^boost search_condition index_name:'search_query'^boost
index_name: The name of the index that you configured in the index schema. This parameter specifies that the search is performed on the source fields of the index to find documents that contain the search query.
search_query: The content to search for.
boost: The weight of the search query. The value must be an integer from 0 to 99. If you do not specify this parameter, the default value is 99.
search_condition: Specifies one or more search conditions. The supported operators, listed in ascending order of priority, are `RANK`, `OR`, `AND`, `ANDNOT`, and `()`. The operators must be in uppercase.
AND: Finds documents that match both search queries. For example, `query=default:'mobile phone' AND default:'bluetooth'` retrieves documents that contain both "mobile phone" and "bluetooth".
OR: Finds documents that match at least one of the search queries. For example, `query=default:'mobile phone' OR default:'bluetooth'` retrieves documents that contain "mobile phone" or "bluetooth".
ANDNOT: Finds documents that match the first search query but not the second. For example, `query=default:'mobile phone' ANDNOT default:'bluetooth'` retrieves documents that contain "mobile phone" but not "bluetooth".
RANK: Finds documents that match the first search query, regardless of whether they match the second. For example, `query=default:'mobile phone' RANK default:'bluetooth'` retrieves documents that contain "mobile phone". The documents are not required to contain "bluetooth". This syntax is useful when a search query should affect scoring but not retrieval. In this example, you can use this syntax with text relevance calculations to rank documents that contain "bluetooth" higher.
Advanced queries
Use one index name for multiple search queries
Syntax:
query=index_name:'search_query'^boost | 'search_query'^boost
query=index_name:'search_query'^boost & 'search_query'^boost
The vertical bar (|) specifies the OR operator. The ampersand (&) specifies the AND operator.
Phrase queries
Syntax:
query=index_name:"search_term"^boost OPERATOR index_name:"search_term"^boost
Enclosing a search query in double quotation marks ("") creates a phrase query, which requires the tokenized terms to be adjacent and in the same order.
To perform a phrase query, enclose the search query in double quotation marks (`""`). A phrase query matches terms that are contiguous and in the same order after tokenization.
Range queries include queries on geographic and numeric data.
weakand queries
Syntax:
query=index_name:('search_query'||'search_query')^number
query=index_name:('search_query')^^number
A weakand query retrieves documents that match only a part of a long search query. You can specify the minimum number of terms that must be matched. You can specify this minimum number in two ways. If you tokenize the query before you send it, use the `^` operator to specify the exact minimum number of matched terms. If the DPI engine tokenizes the query and you do not know the number of terms in advance, use the `^^` operator to set a minimum match ratio. To support scenarios with many terms after tokenization, the `number` parameter for `^^` is a value in thousandths. The minimum number of matched terms is calculated as `(Number of terms after tokenization × number / 1000.0)`, and the result is rounded up.
The performance of a weakand query is between that of an AND query and an OR query. Performance improves as the minimum number of matched terms increases.
Note: The weakand query feature is disabled by default. To use this feature, contact technical support.
Geo-queries
Syntax:
query=index_name:'SHAPE(ARGS...)'
The `SHAPE(ARGS...)` parameter can be one of the following:
Point: `point(LON LAT)`. `LON` is the longitude and `LAT` is the latitude. Use a space to separate them.
Circle: `circle(LON LAT,Radius)`. `LON` is the longitude, `LAT` is the latitude, and `Radius` is the radius in meters.
Rectangle: `rectangle(minLON minLAT,maxLON maxLAT)`. For latitude, `maxY` must be greater than or equal to `minY`. If you reverse the order, the values are automatically adjusted. For longitude, the range from `minX` to `maxX` is interpreted from west to east. If you reverse the order, the range becomes incorrect.
Polygon: `polygon(LON1 LAT1,LON2 LAT2,LON3 LAT3,LON4 LAT4,...)`. The polygon can be convex or concave. The start and end points must be the same. Contiguous edges cannot be collinear. The edges of the polygon cannot self-intersect.
Note:
The index for the query must be of the spatial type.
Enclose the shape in single quotation marks (`'`) for queries on a spatial index. For example: `query=spatial_index:'circle(130.0 10.0,1000.0)'`.
The coordinates for lines and polygons are mapped onto a flat world map to define their range. The system does not consider shapes that cross the 180-degree meridian. Query results for `location` indexes are precise. Results for `line` and `polygon` indexes require row filtering.
Numeric range queries
Syntax:
query=index_name:(value1,value2]
`value1` and `value2` represent the start and end of the numeric range. Range queries support open and closed intervals. A parenthesis `(` indicates an open interval, and a square bracket `]` indicates a closed interval.
Examples:
Open interval: `query = price:(3,100)`. This query retrieves data where `3 < x < 100`.
Closed interval: `query = price:[3,100]`. This query retrieves data where `3 <= x <= 100`.
Half-open interval: `query = price:(3,100]`. This query retrieves data where `3 < x <= 100`.
Unspecified start value: `query=price:(,100)`. This query retrieves data where `x < 100`.
Note:
The index for the query must be of the numeric range type.
Values must be integers. Floating-point numbers are not supported.
Date queries
Syntax:
query=index_name:(start_time,end_time]
The start and end times are integer UNIX timestamps in milliseconds. If you do not specify a start time, the search begins from 0. If you do not specify an end time, the default value is 4102416000000, which is the millisecond timestamp for `2100-01-01 00:00:00`. Date queries also support open and closed intervals.
Note:
The index for the query must be of the date type.
The timestamp must be an integer in milliseconds. If a value exceeds 4102416000000, it is processed as 4102416000000.