All Products
Search
Document Center

OpenSearch:SQL

Last Updated:Oct 19, 2026

Clause description

The query clause is the most basic and indispensable part of a search statement. It specifies which content to search for 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 two TEXT fields, title and subject, 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

Simple query

Syntax:

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

​

  • index_name: the index configured when you define the index schema. The query searches the source fields included in the specified index for documents that contain the search term.

  • search_term: the content to search for.

  • boost: the weight of the search term. The value is of the int type and ranges from 0 to 99. Default value: 99.

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

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

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

  • ANDNOT: returns the set of documents that match the first query but not the second. For example, query=default:'mobile phone' ANDNOT default:'bluetooth' searches for documents that contain "mobile phone" but do not contain "bluetooth".

  • RANK: returns the set of documents that match the first query, whether or not they match the second. For example, query=default:'mobile phone' RANK default:'bluetooth' searches for documents that contain "mobile phone". The documents do not necessarily contain "bluetooth". This syntax is mainly used in scenarios where some search terms affect only scoring, not retrieval. In the preceding example, when used together with text relevance calculation, documents that contain "bluetooth" can be ranked higher.

Advanced query

Multiple search terms sharing one index name

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

Syntax:

query=index_name:"search_term"^boost query_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 include geographic location analysis and numeric analysis.

Geographic location 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 hold. If the values are reversed, they are automatically adjusted. For longitude, the range from 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.

  • The shape in a query on a spatial index must be enclosed in single quotation marks (''), for 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 extent of the lines and polygons. Cases that cross the 180-degree meridian are not considered. Query results from location inverted indexes are exact. Query results from line and polygon inverted indexes need to be filtered.

Numeric range 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) queries data where 3<x<100.

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

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

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

​

Note:

  • The queried index must be a numeric range index.

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

Date query:

Syntax:

query=index_name:(start_time,end_time]

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

​

Note:

  • The queried index must be a date index.

  • Timestamps must be integers accurate to milliseconds. A timestamp greater than 4102416000000 is processed as 4102416000000.