All Products
Search
Document Center

OpenSearch:query clause

Last Updated:Oct 19, 2026

Clause description

The query feature is the most basic and indispensable part of a search statement. It specifies what content to query in which index field. You can also specify multiple query conditions and the relationships between them (AND \ OR \ ANDNOT \ RANK).

For example, you can combine the title and subject fields, both of the TEXT type, to create a shared index named default. A query on the default index can then retrieve documents in which the search term matches the original text of either the title or the subject field.

If you create a separate index named title_search for the title field, a query on the title_search index retrieves a document only if the search term matches the original text of the title field.

Syntax description

Simple query

Query syntax:

query=index_name:'search_term'^boost condition index_name:'search_term'^boost

​

  • index_name: the index information that is configured when you define the index schema. It specifies that the system searches the source fields included in the specified index field for documents that contain the search term.

  • search_term: the content that you want to query.

  • boost: the weight of the search term. The value is of the int type and ranges from 0 to 99 ([0,99]). If you do not set this parameter, the default value 99 is used.

  • condition: You can specify multiple query conditions. The supported relationships are (), AND, OR, ANDNOT, and RANK (must be uppercase). Their precedence, from lowest to highest, is: RANK, OR, AND, ANDNOT, ().

  • AND: the intersection of two search terms. For example, query=default:'mobile phone' AND default:'bluetooth' queries documents that contain both "mobile phone" and "bluetooth".

  • OR: the union of two search terms. For example, query=default:'mobile phone' OR default:'bluetooth' queries documents that contain either "mobile phone" or "bluetooth".

  • ANDNOT: the set of results for which the first query is true and the second query is false. For example, query=default:'mobile phone' ANDNOT default:'bluetooth' queries documents that contain "mobile phone" but do not contain "bluetooth".

  • RANK: the set of results for which the first query is true and the second query may or may not be true. For example, query=default:'mobile phone' RANK default:'bluetooth' queries documents that contain "mobile phone". These documents do not necessarily contain "bluetooth". This syntax is mainly used in scenarios where certain search terms do not affect retrieval but affect only scoring. In the preceding example, when used together with text relevance calculation, it can rank documents that contain "bluetooth" higher.

Advanced query

Multiple search terms sharing one index name

Query syntax:

query=index_name:'search_term'^boost | 'search_term'^boost

query=index_name:'search_term'^boost & 'search_term'^boost

​

'|' indicates an OR relationship between multiple search terms, and '&' indicates an AND relationship between multiple search terms.

​

Phrase query

Query syntax:

query=index_name:"search_term"^boost condition index_name:"search_term"^boost

​

Enclosing the search term in "" indicates a phrase query. This requires that the terms produced by analyzing the search term are adjacent in position and appear in the same order.

​

  • If the search term is enclosed in "", the query is a phrase query. This requires that the terms produced by analyzing the search term are adjacent in position and appear in the same order.

  • Range queries, including geographic location analysis and numeric analysis.

weakand query

Query syntax:

query=index_name:('search_term'||'search_term')^number

query=index_name:('search_term')^^number

In scenarios where the search term is relatively long, a weakand query returns documents in which only some of the terms are matched. The minimum number of terms that must be matched is specified in the query. You can specify the minimum number of matched terms in two ways: If the search term has been tokenized before the query, use the '^' symbol to directly specify the minimum number of matched terms. If the engine performs tokenization itself and the number of terms is not known in advance, use '^^' to specify the minimum proportion of matched terms. To accommodate scenarios in which tokenization produces a very large number of terms, number here is expressed in thousandths. That is, the minimum number of matched terms is the number of terms after tokenization × number/1000.0, rounded up.

The query performance of weakand is between that of an all-AND query and an all-OR query. The more terms that must be matched at minimum, the better the query performance.

Note: The weakand query feature is disabled by default. If you need to use it, contact technical support.

Geographic location query:

Query syntax:

query=index_name:'SHAPE(ARGS...)'

SHAPE(ARGS...) can be one of the following:

  • Point: point(LON LAT). Note: LON indicates the longitude and LAT indicates the latitude, separated by a space.

  • Circle: circle(LON LAT,Radius). Note: LON indicates the longitude, LAT indicates the latitude, and Radius indicates the radius in meters.

  • Rectangle: rectangle(minLON minLAT,maxLON maxLAT). Note: For latitude, maxY>=minY must be true. If the values are reversed, they are automatically adjusted. For longitude, minX to maxX is interpreted from west to east. If the values are reversed, the represented range is incorrect.

  • Polygon: polygon(LON1 LAT1,LON2 LAT2,LON3 LAT3,LON4 LAT4,...). The polygon can be convex or concave. The start point and end point of the polygon must be the same. Two adjacent edges cannot be collinear. The edges of the polygon cannot intersect each other.

​

Note:

  • The queried index must be a spatial index.

  • When you query a Spatial index, enclose the query shape in single quotation marks (''). Example: query=spatial_index:'circle(130.0 10.0,1000.0)'.

  • The point coordinates of lines and polygons are mapped onto a flat world map to determine the ranges of the lines and polygons. Cases that cross the 180-degree meridian are not considered. The query results of location inverted indexes are exact. The query results of line and polygon inverted indexes must be filtered.

Numeric range query:

Query syntax:

query=index_name:(value1,value2]

​

value1 and value2 indicate the start and end values of the numeric range. Numeric range queries support open and closed intervals. '(' indicates an open interval and ']' indicates a closed interval.

Examples:

Open interval query: query = price:(3,100), which queries data where 3<x<100.

Closed interval query: query = price:[3,100], which queries data where 3<=x<=100.

Half-open interval query: query = price:(3,100], which queries data where 3<x<=100.

Start value not specified: query=price:(, 100), which queries data where x<100.

​

Note:

  • The queried index must be a numeric range index.

  • The values must be integers. Floating-point numbers are not supported.

Date query:

Query syntax:

query=index_name:(start_time,end_time]

The start time and end time are integer timestamps accurate to the millisecond. If the start time is not specified, retrieval starts from 0. If the end time is not specified, the default value is 4102416000000 (the timestamp in milliseconds for 2100-01-01 00:00). Date queries also support open and closed date intervals.

​

Note:

  • The queried index must be a date index.

  • Timestamps must be integers accurate to the millisecond. If a timestamp exceeds 4102416000000, it is processed as 4102416000000.