All Products
Search
Document Center

OpenSearch:query clause

Last Updated:Oct 19, 2026

Clause description

The query feature is the most fundamental 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 query term matches the original text of the title field 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 query term matches the original text of the title field.

Syntax description

Simple query

Query syntax:

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

​

  • index_name: the index information that you configure when you define the index schema. It specifies that documents containing the query term are searched for in the source fields included in the specified index field.

  • query_term: the content to query.

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

  • 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 query terms. For example, query=default:'phone' AND default:'bluetooth' queries documents that contain both "phone" and "bluetooth".

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

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

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

Advanced query

Multiple query terms sharing an index name

Query syntax:

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

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

​

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

​

Phrase query

Query syntax:

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

​

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

​

  • If the query term is enclosed in "", the query is a phrase query. This requires that the terms produced by analyzing the query 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:('query_term'||'query_term')^number

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

In scenarios where the query term is relatively long, a weakand query returns documents that match only some of the terms. 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 query is already tokenized before it is sent, use the '^' symbol to directly specify the minimum number of matched terms. If the engine performs tokenization itself and the number of resulting terms is not known in advance, use '^^' to specify the minimum proportion of matched terms. To accommodate scenarios where 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 query terms after tokenization × number/1000.0, rounded up.

The query performance of weakand is between that of all-AND and all-OR queries. The larger the minimum number of matched terms, the better the query performance.

Note: The weakand query feature is disabled by default. 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 must be >= minY. If they are reversed, they are automatically adjusted. For longitude, the range from minX to maxX is interpreted from west to east. If they 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 query shape for 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 flattened world map to determine the extent of the lines and polygons. Crossing the 180-degree meridian is not considered. Query results of location inverted indexes are exact. Query results of line and polygon inverted indexes need to 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) 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.

No start value 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

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, 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 the millisecond. Values greater than 4102416000000 are processed as 4102416000000.