Class SearchRequest
Request for Search
https://opensearch.org/docs/latest/api-reference/search/
Inheritance
Inherited Members
Namespace: OpenSearch.Client
Assembly: OpenSearch.Client.dll
Syntax
[DataContract]
public class SearchRequest : PlainRequestBase<SearchRequestParameters>, ISearchRequest, ITypedSearchRequest, IRequest<SearchRequestParameters>, IRequest
Constructors
| Edit this page View SourceSearchRequest()
/_search
Declaration
public SearchRequest()
SearchRequest(Indices)
/{index}/_search
Declaration
public SearchRequest(Indices index)
Parameters
| Type | Name | Description |
|---|---|---|
| Indices | index | Optional, accepts null |
Properties
| Edit this page View SourceAggregations
Specifies the aggregations to perform
Declaration
public AggregationDictionary Aggregations { get; set; }
Property Value
| Type | Description |
|---|---|
| AggregationDictionary |
AllowNoIndices
If false, the request returns an error if any wildcard expression, index alias, or _all value targets only missing or closed
indexes. This behavior applies even if the request targets other open indexes. For example, a request targeting foo*,bar* returns
an error if an index starts with foo but no index starts with bar.
Declaration
public bool? AllowNoIndices { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
AllowPartialSearchResults
If true, returns partial results if there are shard request timeouts or shard failures. If false, returns an error with no
partial results.
Declaration
public bool? AllowPartialSearchResults { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
AnalyzeWildcard
If true, wildcard and prefix queries are analyzed. This parameter can only be used when the q query string parameter is specified.
Declaration
public bool? AnalyzeWildcard { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Analyzer
Analyzer to use for the query string. This parameter can only be used when the q query string parameter is specified.
Declaration
public string Analyzer { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
BatchedReduceSize
The number of shard results that should be reduced at once on the coordinating node. This value should be used as a protection mechanism to reduce the memory overhead per search request if the potential number of shards in the request can be large.
Declaration
public int? BatchedReduceSize { get; set; }
Property Value
| Type | Description |
|---|---|
| int? |
CancelAfterTimeInterval
The time after which the search request will be canceled. Request-level parameter takes precedence over cancel_after_time_interval
cluster setting.
Declaration
public Time CancelAfterTimeInterval { get; set; }
Property Value
| Type | Description |
|---|---|
| Time |
CcsMinimizeRoundtrips
If true, network round-trips between the coordinating node and the remote clusters are minimized when executing cross-cluster
search (CCS) requests.
Declaration
public bool? CcsMinimizeRoundtrips { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Collapse
Allows to collapse search results based on field values. The collapsing is done by selecting only the top sorted document per collapse key. For instance the query below retrieves the best tweet for each user and sorts them by number of likes.
NOTE: The collapsing is applied to the top hits only and does not affect aggregations. You can only collapse to a depth of 2.
Declaration
public IFieldCollapse Collapse { get; set; }
Property Value
| Type | Description |
|---|---|
| IFieldCollapse |
DefaultOperator
The default operator for query string query: AND or OR. This parameter can only be used when the q query string parameter is
specified.
Declaration
public DefaultOperator? DefaultOperator { get; set; }
Property Value
| Type | Description |
|---|---|
| DefaultOperator? |
Df
Field to use as default where no field prefix is given in the query string. This parameter can only be used when the q query string parameter is specified.
Declaration
public string Df { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
DocValueFields
Declaration
public Fields DocValueFields { get; set; }
Property Value
| Type | Description |
|---|---|
| Fields |
ExpandWildcards
Type of index that wildcard patterns can match. If the request can target data streams, this argument determines whether wildcard
expressions match hidden data streams. Supports comma-separated values, such as open,hidden.
Declaration
public ExpandWildcards? ExpandWildcards { get; set; }
Property Value
| Type | Description |
|---|---|
| ExpandWildcards? |
Explain
Enables explanation for each hit on how its score was computed
Declaration
public bool? Explain { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Ext
Declaration
public IDictionary<string, object> Ext { get; set; }
Property Value
| Type | Description |
|---|---|
| IDictionary<string, object> |
Fields
BETA: Allows for retrieving a list of document fields in the search response.
This functionality is in beta and is subject to change.
Declaration
public Fields Fields { get; set; }
Property Value
| Type | Description |
|---|---|
| Fields |
From
The starting from index of the hits to return. Defaults to 0.
Declaration
public int? From { get; set; }
Property Value
| Type | Description |
|---|---|
| int? |
Highlight
Allow to highlight search results on one or more fields. The implementation uses the either lucene fast-vector-highlighter or highlighter.
Declaration
public IHighlight Highlight { get; set; }
Property Value
| Type | Description |
|---|---|
| IHighlight |
HttpMethod
Declaration
protected override HttpMethod HttpMethod { get; }
Property Value
| Type | Description |
|---|---|
| HttpMethod |
Overrides
| Edit this page View SourceIgnoreThrottled
If true, concrete, expanded or aliased indexes will be ignored when frozen.
Declaration
public bool? IgnoreThrottled { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
IgnoreUnavailable
If false, the request returns an error if it targets a missing or closed index.
Declaration
public bool? IgnoreUnavailable { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
IncludeNamedQueriesScore
Indicates whether hit.matched_queries should be rendered as a map that includes the name of the matched query associated with its
score (true) or as an array containing the name of the matched queries (false).
Declaration
public bool? IncludeNamedQueriesScore { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
IndicesBoost
Allows to configure different boost level per index when searching across more than one indices. This is very handy when hits coming from one index matter more than hits coming from another index (think social graph where each user has an index).
Declaration
public IDictionary<IndexName, double> IndicesBoost { get; set; }
Property Value
| Type | Description |
|---|---|
| IDictionary<IndexName, double> |
Lenient
If true, format-based query failures (such as providing text to a numeric field) in the query string will be ignored. This
parameter can only be used when the q query string parameter is specified.
Declaration
public bool? Lenient { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
MaxConcurrentShardRequests
Defines the number of concurrent shard requests per node this search executes concurrently. This value should be used to limit the impact of the search on the cluster in order to limit the number of concurrent shard requests.
Declaration
public int? MaxConcurrentShardRequests { get; set; }
Property Value
| Type | Description |
|---|---|
| int? |
MinScore
Allows to filter out documents based on a minimum score
Declaration
public double? MinScore { get; set; }
Property Value
| Type | Description |
|---|---|
| double? |
PhaseTook
Indicates whether to return phase-level took time values in the response.
Declaration
public bool? PhaseTook { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
PointInTime
Search against a dataset frozen at a point-in-time (PIT)
https://opensearch.org/docs/latest/search-plugins/point-in-time/Declaration
public IPointInTime PointInTime { get; set; }
Property Value
| Type | Description |
|---|---|
| IPointInTime |
Remarks
Supported by OpenSearch servers of version 2.4.0 or greater.
See Also
| Edit this page View SourcePostFilter
Specify a query to apply to the search hits at the very end of a search request, after aggregations have already been calculated. Useful when both search hits and aggregations will be returned in the response, and a filter should only be applied to the search hits.
Declaration
public QueryContainer PostFilter { get; set; }
Property Value
| Type | Description |
|---|---|
| QueryContainer |
PreFilterShardSize
Defines a threshold that enforces a pre-filter roundtrip to prefilter search shards based on query rewriting if the number of shards the search request expands to exceeds the threshold. This filter roundtrip can limit the number of shards significantly if for instance a shard can not match any documents based on its rewrite method (if date filters are mandatory to match but the shard bounds and the query are disjoint). When unspecified, the pre-filter phase is executed if any of these conditions is met: the request targets more than 128 shards; the request targets one or more read-only index; the primary sort of the query targets an indexed field.
Declaration
public int? PreFilterShardSize { get; set; }
Property Value
| Type | Description |
|---|---|
| int? |
Preference
Nodes and shards used for the search. By default, OpenSearch selects from eligible nodes and shards using adaptive replica selection,
accounting for allocation awareness. Valid values are: _only_local to run the search only on shards on the local node;
_local to, if possible, run the search on shards on the local node, or if not, select shards using the default method;
_only_nodes:<node-id>,<node-id> to run the search on only the specified nodes IDs, where, if suitable shards exist on
more than one selected node, use shards on those nodes using the default method, or if none of the specified nodes are available, select
shards from any available node using the default method; _prefer_nodes:<node-id>,<node-id> to if possible, run the
search on the specified nodes IDs, or if not, select shards using the default method; shards:<shard>,<shard> to run
the search only on the specified shards; <custom-string> (any string that does not start with ) to route searches
with the same <custom-string> to the same shards in the same order.
Declaration
public string Preference { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Profile
The Profile API provides detailed timing information about the execution of individual components in a query. It gives the user insight into how queries are executed at a low level so that the user can understand why certain queries are slow, and take steps to improve their slow queries.
Declaration
public bool? Profile { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Query
Specify the search query to perform
Declaration
public QueryContainer Query { get; set; }
Property Value
| Type | Description |
|---|---|
| QueryContainer |
QueryOnQueryString
Query in the Lucene query string syntax using query parameter search. Query parameter searches do not support the full OpenSearch Query DSL but are handy for testing.
Declaration
public string QueryOnQueryString { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
RequestCache
If true, the caching of search results is enabled for requests where size is 0. Defaults to index level settings.
Declaration
public bool? RequestCache { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Rescore
Specify one or more queries to use for rescoring
Declaration
public IList<IRescore> Rescore { get; set; }
Property Value
| Type | Description |
|---|---|
| IList<IRescore> |
Routing
A document is routed to a particular shard in an index using the following formula
shard_num = hash(_routing) % num_primary_shards
OpenSearch will use the document id if not provided.
For requests that are constructed from/for a document OpenSearch.Client will automatically infer the routing key if that document has a JoinField or a routing mapping on for its type exists on ConnectionSettings
Declaration
public Routing Routing { get; set; }
Property Value
| Type | Description |
|---|---|
| Routing |
RuntimeFields
Specifies runtime fields which exist only as part of the query.
Declaration
public IRuntimeFields RuntimeFields { get; set; }
Property Value
| Type | Description |
|---|---|
| IRuntimeFields |
ScriptFields
Allows to return a script evaluation (based on different fields) for each hit
Declaration
public IScriptFields ScriptFields { get; set; }
Property Value
| Type | Description |
|---|---|
| IScriptFields |
Scroll
Period to retain the search context for scrolling. See Scroll search results. By default, this value cannot exceed 1d (24 hours).
You can change this limit using the search.max_keep_alive cluster-level setting.
Declaration
public Time Scroll { get; set; }
Property Value
| Type | Description |
|---|---|
| Time |
SearchAfter
Sort values that can be used to start returning results "after" any document in the result list.
Declaration
public IList<object> SearchAfter { get; set; }
Property Value
| Type | Description |
|---|---|
| IList<object> |
SearchPipeline
Customizable sequence of processing stages applied to search queries.
Declaration
public string SearchPipeline { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
SearchType
How distributed term frequencies are calculated for relevance scoring.
Declaration
public SearchType? SearchType { get; set; }
Property Value
| Type | Description |
|---|---|
| SearchType? |
Self
Declaration
protected ISearchRequest Self { get; }
Property Value
| Type | Description |
|---|---|
| ISearchRequest |
SequenceNumberPrimaryTerm
If true, returns sequence number and primary term of the last modification of each hit.
Declaration
public bool? SequenceNumberPrimaryTerm { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Size
The number of hits to return. Defaults to 10.
Declaration
public int? Size { get; set; }
Property Value
| Type | Description |
|---|---|
| int? |
Slice
For scroll queries that return a lot of documents it is possible to split the scroll in multiple slices which can be consumed independently
Declaration
public ISlicedScroll Slice { get; set; }
Property Value
| Type | Description |
|---|---|
| ISlicedScroll |
Sort
Specifies how to sort the search hits
Declaration
public IList<ISort> Sort { get; set; }
Property Value
| Type | Description |
|---|---|
| IList<ISort> |
Source
Specify how the _source field is returned for each search hit.
When true, _source retrieval is enabled (default)
When false, _source retrieval is disabled, and no _source will be returned for each hit
When ISourceFilter is specified, fields to include/exclude can be controlled
Declaration
public Union<bool, ISourceFilter> Source { get; set; }
Property Value
| Type | Description |
|---|---|
| Union<bool, ISourceFilter> |
Stats
Specific tag of the request for logging and statistical purposes.
Declaration
public string[] Stats { get; set; }
Property Value
| Type | Description |
|---|---|
| string[] |
StoredFields
Declaration
public Fields StoredFields { get; set; }
Property Value
| Type | Description |
|---|---|
| Fields |
Suggest
The suggest feature suggests similar looking terms based on a provided text by using a suggester
Declaration
public ISuggestContainer Suggest { get; set; }
Property Value
| Type | Description |
|---|---|
| ISuggestContainer |
SuggestField
Specifies which field to use for suggestions.
Declaration
public Field SuggestField { get; set; }
Property Value
| Type | Description |
|---|---|
| Field |
SuggestMode
Specifies the suggest mode. This parameter can only be used when the suggest_field and suggest_text query string parameters
are specified.
Declaration
public SuggestMode? SuggestMode { get; set; }
Property Value
| Type | Description |
|---|---|
| SuggestMode? |
SuggestSize
Number of suggestions to return. This parameter can only be used when the suggest_field and suggest_text query string
parameters are specified.
Declaration
public int? SuggestSize { get; set; }
Property Value
| Type | Description |
|---|---|
| int? |
SuggestText
The source text for which the suggestions should be returned. This parameter can only be used when the suggest_field and
suggest_text query string parameters are specified.
Declaration
public string SuggestText { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
TerminateAfter
The maximum number of documents to collect for each shard, upon reaching which the query execution will terminate early. If set, the response will have a boolean field terminated_early to indicate whether the query execution has actually terminated_early.
Declaration
public long? TerminateAfter { get; set; }
Property Value
| Type | Description |
|---|---|
| long? |
Timeout
A search timeout, bounding the search request to be executed within the specified time value and bail with the hits accumulated up to that point, when expired. Defaults to no timeout.
Declaration
public string Timeout { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
TotalHitsAsInteger
Indicates whether hits.total should be rendered as an integer or an object in the rest search response.
Declaration
public bool? TotalHitsAsInteger { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
TrackScores
Make sure we keep calculating score even if we are sorting on a field.
Declaration
public bool? TrackScores { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
TrackTotalHits
Declaration
public TrackTotalHits TrackTotalHits { get; set; }
Property Value
| Type | Description |
|---|---|
| TrackTotalHits |
TypedKeys
If true, aggregation and suggester names are be prefixed by their respective types in the response.
Declaration
public bool? TypedKeys { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
VerbosePipeline
Enables or disables verbose mode for the search pipeline. When verbose mode is enabled, detailed information about each processor in the search pipeline is included in the search response. This includes the processor name, execution status, input, output, and time taken for processing. This parameter is primarily intended for debugging purposes, allowing users to track how data flows and transforms through the search pipeline.
Declaration
public bool? VerbosePipeline { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Remarks
Supported by OpenSearch servers of version 3.0.0 or greater.
Version
Return a version for each search hit
Declaration
public bool? Version { get; set; }
Property Value
| Type | Description |
|---|---|
| bool? |
Methods
| Edit this page View SourceRequestDefaults(SearchRequestParameters)
Allows a request implementation to set certain request parameter defaults, use sparingly!
Declaration
protected override sealed void RequestDefaults(SearchRequestParameters parameters)
Parameters
| Type | Name | Description |
|---|---|---|
| SearchRequestParameters | parameters |
Overrides
| Edit this page View SourceResolveUrl(RouteValues, IConnectionSettingsValues)
Declaration
protected override string ResolveUrl(RouteValues routeValues, IConnectionSettingsValues settings)
Parameters
| Type | Name | Description |
|---|---|---|
| RouteValues | routeValues | |
| IConnectionSettingsValues | settings |
Returns
| Type | Description |
|---|---|
| string |