OpenSearch provides a set of clauses that control how search results are queried, filtered, sorted, aggregated, and exported. Each clause handles a specific aspect of search processing, and you can combine them to build efficient and flexible search solutions.
Clause function overview
The query clause is a required component of every search statement. It specifies the index field and the content to search for, and supports multiple query conditions joined by AND, OR, ANDNOT, or RANK. For more information, see Index retrieval - query clause.
The filter clause screens documents based on specific conditions and narrows the results retrieved by the query clause to produce the final result set. For more information, see Result filtering - filter clause.
A keyword search can return thousands of documents, making it impractical to browse them all. The aggregate clause lets you group results and compute statistics instead. For more information, see Grouping and statistics - aggregate clause.
The distinct clause ensures result diversity. When multiple documents from the same user have high relevance scores, they can dominate the top results and fill an entire page. The distinct clause extracts documents on a per-user basis so that results from different users are displayed. For more information, see Aggregation and diversification - distinct clause.
The sort clause controls how results are ordered by specifying the sort field and direction (ascending or descending). For more information, see Global sorting - sort clause.
The kvpairs clause defines parameters for variable parts of a sort expression, allowing you to pass values to specific feature functions in a search statement. For more information, see Custom parameter passing - kvpair clause.
The config clause sets the starting position of search results, the number of results to return, the display format, and the number of documents to include in the fine sort expression. For more information, see Query pagination - config clause.
Traditional search engines limit the number of results returned — for example, a maximum of 5,000 documents. When you need to retrieve a larger number of results for analysis, use the scroll method. For more information, see Batch export of documents - scroll method.