search
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Run a search.
Get search hits that match the query defined in the request.You can provide search queries using the `q` query string parameter or therequest body.If both are specified, only the query parameter is used.
If the Elasticsearch security features are enabled, you must have the readindex privilege for the target data stream, index, or alias. Forcross-cluster search, refer to the documentation about configuring CCSprivileges.To search a point in time (PIT) for an alias, you must have the `read` indexprivilege for the alias's data streams or indices.
**Search slicing**
When paging through a large number of documents, it can be helpful to splitthe search into multiple slices to consume them independently with the`slice` and `pit` properties.By default the splitting is done first on the shards, then locally on eachshard.The local splitting partitions the shard into contiguous ranges based onLucene document IDs.
For instance if the number of shards is equal to 2 and you request 4 slices,the slices 0 and 2 are assigned to the first shard and the slices 1 and 3 areassigned to the second shard.
IMPORTANT: The same point-in-time ID should be used for all slices.If different PIT IDs are used, slices can overlap and miss documents.This situation can occur because the splitting criterion is based on Lucenedocument IDs, which are not stable across changes to the index.
Index¶
- Variables
- type NewSearch
- type Request
- type Response
- type Search
- func (r *Search) Aggregations(aggregations map[string]types.Aggregations) *Search
- func (r *Search) AllowNoIndices(allownoindices bool) *Search
- func (r *Search) AllowPartialSearchResults(allowpartialsearchresults bool) *Search
- func (r *Search) AnalyzeWildcard(analyzewildcard bool) *Search
- func (r *Search) Analyzer(analyzer string) *Search
- func (r *Search) BatchedReduceSize(batchedreducesize string) *Search
- func (r *Search) CcsMinimizeRoundtrips(ccsminimizeroundtrips bool) *Search
- func (r *Search) Collapse(collapse *types.FieldCollapse) *Search
- func (r *Search) DefaultOperator(defaultoperator operator.Operator) *Search
- func (r *Search) Df(df string) *Search
- func (r Search) Do(providedCtx context.Context) (*Response, error)
- func (r *Search) DocvalueFields(docvaluefields ...types.FieldAndFormat) *Search
- func (r *Search) ErrorTrace(errortrace bool) *Search
- func (r *Search) ExpandWildcards(expandwildcards ...expandwildcard.ExpandWildcard) *Search
- func (r *Search) Explain(explain bool) *Search
- func (r *Search) Ext(ext map[string]json.RawMessage) *Search
- func (r *Search) Fields(fields ...types.FieldAndFormat) *Search
- func (r *Search) FilterPath(filterpaths ...string) *Search
- func (r *Search) ForceSyntheticSource(forcesyntheticsource bool) *Search
- func (r *Search) From(from int) *Search
- func (r *Search) Header(key, value string) *Search
- func (r *Search) Highlight(highlight *types.Highlight) *Search
- func (r *Search) HttpRequest(ctx context.Context) (*http.Request, error)
- func (r *Search) Human(human bool) *Search
- func (r *Search) IgnoreThrottled(ignorethrottled bool) *Search
- func (r *Search) IgnoreUnavailable(ignoreunavailable bool) *Search
- func (r *Search) IncludeNamedQueriesScore(includenamedqueriesscore bool) *Search
- func (r *Search) Index(index string) *Search
- func (r *Search) IndicesBoost(indicesboosts ...map[string]types.Float64) *Search
- func (r *Search) Knn(knns ...types.KnnSearch) *Search
- func (r *Search) Lenient(lenient bool) *Search
- func (r *Search) MaxConcurrentShardRequests(maxconcurrentshardrequests string) *Search
- func (r *Search) MinCompatibleShardNode(versionstring string) *Search
- func (r *Search) MinScore(minscore types.Float64) *Search
- func (r Search) Perform(providedCtx context.Context) (*http.Response, error)
- func (r *Search) Pit(pit *types.PointInTimeReference) *Search
- func (r *Search) PostFilter(postfilter *types.Query) *Search
- func (r *Search) PreFilterShardSize(prefiltershardsize string) *Search
- func (r *Search) Preference(preference string) *Search
- func (r *Search) Pretty(pretty bool) *Search
- func (r *Search) Profile(profile bool) *Search
- func (r *Search) Q(q string) *Search
- func (r *Search) Query(query *types.Query) *Search
- func (r *Search) Rank(rank *types.RankContainer) *Search
- func (r *Search) Raw(raw io.Reader) *Search
- func (r *Search) Request(req *Request) *Search
- func (r *Search) RequestCache(requestcache bool) *Search
- func (r *Search) Rescore(rescores ...types.Rescore) *Search
- func (r *Search) RestTotalHitsAsInt(resttotalhitsasint bool) *Search
- func (r *Search) Retriever(retriever *types.RetrieverContainer) *Search
- func (r *Search) Routing(routing string) *Search
- func (r *Search) RuntimeMappings(runtimefields types.RuntimeFields) *Search
- func (r *Search) ScriptFields(scriptfields map[string]types.ScriptField) *Search
- func (r *Search) Scroll(duration string) *Search
- func (r *Search) SearchAfter(sortresults ...types.FieldValue) *Search
- func (r *Search) SearchType(searchtype searchtype.SearchType) *Search
- func (r *Search) SeqNoPrimaryTerm(seqnoprimaryterm bool) *Search
- func (r *Search) Size(size int) *Search
- func (r *Search) Slice(slice *types.SlicedScroll) *Search
- func (r *Search) Sort(sorts ...types.SortCombinations) *Search
- func (r *Search) SourceExcludes_(fields ...string) *Search
- func (r *Search) SourceIncludes_(fields ...string) *Search
- func (r *Search) Source_(sourceconfig types.SourceConfig) *Search
- func (r *Search) Stats(stats ...string) *Search
- func (r *Search) StoredFields(fields ...string) *Search
- func (r *Search) Suggest(suggest *types.Suggester) *Search
- func (r *Search) SuggestField(field string) *Search
- func (r *Search) SuggestMode(suggestmode suggestmode.SuggestMode) *Search
- func (r *Search) SuggestSize(suggestsize string) *Search
- func (r *Search) SuggestText(suggesttext string) *Search
- func (r *Search) TerminateAfter(terminateafter int64) *Search
- func (r *Search) Timeout(timeout string) *Search
- func (r *Search) TrackScores(trackscores bool) *Search
- func (r *Search) TrackTotalHits(trackhits types.TrackHits) *Search
- func (r *Search) TypedKeys(typedkeys bool) *Search
- func (r *Search) Version(version bool) *Search
Constants¶
This section is empty.
Variables¶
var ErrBuildPath =errors.New("cannot build path, check for missing path parameters")ErrBuildPath is returned in case of missing parameters within the build of the request.
Functions¶
This section is empty.
Types¶
typeNewSearch¶
type NewSearch func() *Search
NewSearch type alias for index.
funcNewSearchFunc¶
func NewSearchFunc(tpelastictransport.Interface)NewSearch
NewSearchFunc returns a new instance of Search with the provided transport.Used in the index of the library this allows to retrieve every apis in once place.
typeRequest¶
type Request struct {// Aggregations Defines the aggregations that are run as part of the search request.Aggregations map[string]types.Aggregations `json:"aggregations,omitempty"`// Collapse Collapses search results the values of the specified field.Collapse *types.FieldCollapse `json:"collapse,omitempty"`// DocvalueFields An array of wildcard (`*`) field patterns.// The request returns doc values for field names matching these patterns in the// `hits.fields` property of the response.DocvalueFields []types.FieldAndFormat `json:"docvalue_fields,omitempty"`// Explain If `true`, the request returns detailed information about score computation// as part of a hit.Explain *bool `json:"explain,omitempty"`// Ext Configuration of search extensions defined by Elasticsearch plugins.Ext map[string]json.RawMessage `json:"ext,omitempty"`// Fields An array of wildcard (`*`) field patterns.// The request returns values for field names matching these patterns in the// `hits.fields` property of the response.Fields []types.FieldAndFormat `json:"fields,omitempty"`// From The starting document offset, which must be non-negative.// By default, you cannot page through more than 10,000 hits using the `from`// and `size` parameters.// To page through more hits, use the `search_after` parameter.From *int `json:"from,omitempty"`// Highlight Specifies the highlighter to use for retrieving highlighted snippets from one// or more fields in your search results.Highlight *types.Highlight `json:"highlight,omitempty"`// IndicesBoost Boost the `_score` of documents from specified indices.// The boost value is the factor by which scores are multiplied.// A boost value greater than `1.0` increases the score.// A boost value between `0` and `1.0` decreases the score.IndicesBoost []map[string]types.Float64 `json:"indices_boost,omitempty"`// Knn The approximate kNN search to run.Knn []types.KnnSearch `json:"knn,omitempty"`// MinScore The minimum `_score` for matching documents.// Documents with a lower `_score` are not included in search results and// results collected by aggregations.MinScore *types.Float64 `json:"min_score,omitempty"`// Pit Limit the search to a point in time (PIT).// If you provide a PIT, you cannot specify an `<index>` in the request path.Pit *types.PointInTimeReference `json:"pit,omitempty"`// PostFilter Use the `post_filter` parameter to filter search results.// The search hits are filtered after the aggregations are calculated.// A post filter has no impact on the aggregation results.PostFilter *types.Query `json:"post_filter,omitempty"`// Profile Set to `true` to return detailed timing information about the execution of// individual components in a search request.// NOTE: This is a debugging tool and adds significant overhead to search// execution.Profile *bool `json:"profile,omitempty"`// Query The search definition using the Query DSL.Query *types.Query `json:"query,omitempty"`// Rank The Reciprocal Rank Fusion (RRF) to use.Rank *types.RankContainer `json:"rank,omitempty"`// Rescore Can be used to improve precision by reordering just the top (for example 100// - 500) documents returned by the `query` and `post_filter` phases.Rescore []types.Rescore `json:"rescore,omitempty"`// Retriever A retriever is a specification to describe top documents returned from a// search.// A retriever replaces other elements of the search API that also return top// documents such as `query` and `knn`.Retriever *types.RetrieverContainer `json:"retriever,omitempty"`// RuntimeMappings One or more runtime fields in the search request.// These fields take precedence over mapped fields with the same name.RuntimeMappingstypes.RuntimeFields `json:"runtime_mappings,omitempty"`// ScriptFields Retrieve a script evaluation (based on different fields) for each hit.ScriptFields map[string]types.ScriptField `json:"script_fields,omitempty"`// SearchAfter Used to retrieve the next page of hits using a set of sort values from the// previous page.SearchAfter []types.FieldValue `json:"search_after,omitempty"`// SeqNoPrimaryTerm If `true`, the request returns sequence number and primary term of the last// modification of each hit.SeqNoPrimaryTerm *bool `json:"seq_no_primary_term,omitempty"`// Size The number of hits to return, which must not be negative.// By default, you cannot page through more than 10,000 hits using the `from`// and `size` parameters.// To page through more hits, use the `search_after` property.Size *int `json:"size,omitempty"`// Slice Split a scrolled search into multiple slices that can be consumed// independently.Slice *types.SlicedScroll `json:"slice,omitempty"`// Sort A comma-separated list of <field>:<direction> pairs.Sort []types.SortCombinations `json:"sort,omitempty"`// Source_ The source fields that are returned for matching documents.// These fields are returned in the `hits._source` property of the search// response.// If the `stored_fields` property is specified, the `_source` property defaults// to `false`.// Otherwise, it defaults to `true`.Source_types.SourceConfig `json:"_source,omitempty"`// Stats The stats groups to associate with the search.// Each group maintains a statistics aggregation for its associated searches.// You can retrieve these stats using the indices stats API.Stats []string `json:"stats,omitempty"`// StoredFields A comma-separated list of stored fields to return as part of a hit.// If no fields are specified, no stored fields are included in the response.// If this field is specified, the `_source` property defaults to `false`.// You can pass `_source: true` to return both source fields and stored fields// in the search response.StoredFields []string `json:"stored_fields,omitempty"`// Suggest Defines a suggester that provides similar looking terms based on a provided// text.Suggest *types.Suggester `json:"suggest,omitempty"`// TerminateAfter The maximum number of documents to collect for each shard.// If a query reaches this limit, Elasticsearch terminates the query early.// Elasticsearch collects documents before sorting.//// IMPORTANT: Use with caution.// Elasticsearch applies this property to each shard handling the request.// When possible, let Elasticsearch perform early termination automatically.// Avoid specifying this property for requests that target data streams with// backing indices across multiple data tiers.//// If set to `0` (default), the query does not terminate early.TerminateAfter *int64 `json:"terminate_after,omitempty"`// Timeout The period of time to wait for a response from each shard.// If no response is received before the timeout expires, the request fails and// returns an error.// Defaults to no timeout.Timeout *string `json:"timeout,omitempty"`// TrackScores If `true`, calculate and return document scores, even if the scores are not// used for sorting.TrackScores *bool `json:"track_scores,omitempty"`// TrackTotalHits Number of hits matching the query to count accurately.// If `true`, the exact number of hits is returned at the cost of some// performance.// If `false`, the response does not include the total number of hits matching// the query.TrackTotalHitstypes.TrackHits `json:"track_total_hits,omitempty"`// Version If `true`, the request returns the document version as part of a hit.Version *bool `json:"version,omitempty"`}Request holds the request body struct for the package search
func (*Request)FromJSON¶added inv8.5.0
FromJSON allows to load an arbitrary json into the request structure
func (*Request)UnmarshalJSON¶added inv8.12.1
typeResponse¶added inv8.7.0
type Response struct {Aggregations map[string]types.Aggregate `json:"aggregations,omitempty"`Clusters_ *types.ClusterStatistics `json:"_clusters,omitempty"`Fields map[string]json.RawMessage `json:"fields,omitempty"`// Hits The returned documents and metadata.Hitstypes.HitsMetadata `json:"hits"`MaxScore *types.Float64 `json:"max_score,omitempty"`NumReducePhases *int64 `json:"num_reduce_phases,omitempty"`PitId *string `json:"pit_id,omitempty"`Profile *types.Profile `json:"profile,omitempty"`// ScrollId_ The identifier for the search and its search context.// You can use this scroll ID with the scroll API to retrieve the next batch of// search results for the request.// This property is returned only if the `scroll` query parameter is specified// in the request.ScrollId_ *string `json:"_scroll_id,omitempty"`// Shards_ A count of shards used for the request.Shards_types.ShardStatistics `json:"_shards"`Suggest map[string][]types.Suggest `json:"suggest,omitempty"`TerminatedEarly *bool `json:"terminated_early,omitempty"`// TimedOut If `true`, the request timed out before completion; returned results may be// partial or empty.TimedOutbool `json:"timed_out"`// Took The number of milliseconds it took Elasticsearch to run the request.// This value is calculated by measuring the time elapsed between receipt of a// request on the coordinating node and the time at which the coordinating node// is ready to send the response.// It includes://// * Communication time between the coordinating node and data nodes// * Time the request spends in the search thread pool, queued for execution// * Actual run time//// It does not include://// * Time needed to send the request to Elasticsearch// * Time needed to serialize the JSON response// * Time needed to send the response to a clientTookint64 `json:"took"`}Response holds the response body struct for the package search
func (*Response)UnmarshalJSON¶added inv8.7.0
typeSearch¶
type Search struct {// contains filtered or unexported fields}funcNew¶
func New(tpelastictransport.Interface) *Search
Run a search.
Get search hits that match the query defined in the request.You can provide search queries using the `q` query string parameter or therequest body.If both are specified, only the query parameter is used.
If the Elasticsearch security features are enabled, you must have the readindex privilege for the target data stream, index, or alias. Forcross-cluster search, refer to the documentation about configuring CCSprivileges.To search a point in time (PIT) for an alias, you must have the `read` indexprivilege for the alias's data streams or indices.
**Search slicing**
When paging through a large number of documents, it can be helpful to splitthe search into multiple slices to consume them independently with the`slice` and `pit` properties.By default the splitting is done first on the shards, then locally on eachshard.The local splitting partitions the shard into contiguous ranges based onLucene document IDs.
For instance if the number of shards is equal to 2 and you request 4 slices,the slices 0 and 2 are assigned to the first shard and the slices 1 and 3 areassigned to the second shard.
IMPORTANT: The same point-in-time ID should be used for all slices.If different PIT IDs are used, slices can overlap and miss documents.This situation can occur because the splitting criterion is based on Lucenedocument IDs, which are not stable across changes to the index.
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html
func (*Search)Aggregations¶added inv8.9.0
func (r *Search) Aggregations(aggregations map[string]types.Aggregations) *Search
Aggregations Defines the aggregations that are run as part of the search request.API name: aggregations
func (*Search)AllowNoIndices¶
AllowNoIndices If `false`, the request returns an error if any wildcard expression, indexalias, or `_all` value targets only missing or closed indices.This behavior applies even if the request targets other open indices.For example, a request targeting `foo*,bar*` returns an error if an indexstarts with `foo` but no index starts with `bar`.API name: allow_no_indices
func (*Search)AllowPartialSearchResults¶
AllowPartialSearchResults If `true` and there are shard request timeouts or shard failures, the requestreturns partial results.If `false`, it returns an error with no partial results.
To override the default behavior, you can set the`search.default_allow_partial_results` cluster setting to `false`.API name: allow_partial_search_results
func (*Search)AnalyzeWildcard¶
AnalyzeWildcard If `true`, wildcard and prefix queries are analyzed.This parameter can be used only when the `q` query string parameter isspecified.API name: analyze_wildcard
func (*Search)Analyzer¶
Analyzer The analyzer to use for the query string.This parameter can be used only when the `q` query string parameter isspecified.API name: analyzer
func (*Search)BatchedReduceSize¶
BatchedReduceSize The number of shard results that should be reduced at once on thecoordinating node.If the potential number of shards in the request can be large, this valueshould be used as a protection mechanism to reduce the memory overhead persearch request.API name: batched_reduce_size
func (*Search)CcsMinimizeRoundtrips¶
CcsMinimizeRoundtrips If `true`, network round-trips between the coordinating node and the remoteclusters are minimized when running cross-cluster search (CCS) requests.API name: ccs_minimize_roundtrips
func (*Search)Collapse¶added inv8.9.0
func (r *Search) Collapse(collapse *types.FieldCollapse) *Search
Collapse Collapses search results the values of the specified field.API name: collapse
func (*Search)DefaultOperator¶
DefaultOperator The default operator for the query string query: `AND` or `OR`.This parameter can be used only when the `q` query string parameter isspecified.API name: default_operator
func (*Search)Df¶
Df The field to use as a default when no field prefix is given in the querystring.This parameter can be used only when the `q` query string parameter isspecified.API name: df
func (Search)Do¶
Do runs the request through the transport, handle the response and returns a search.Response
func (*Search)DocvalueFields¶
func (r *Search) DocvalueFields(docvaluefields ...types.FieldAndFormat) *Search
DocvalueFields An array of wildcard (`*`) field patterns.The request returns doc values for field names matching these patterns in the`hits.fields` property of the response.API name: docvalue_fields
func (*Search)ErrorTrace¶added inv8.14.0
ErrorTrace When set to `true` Elasticsearch will include the full stack trace of errorswhen they occur.API name: error_trace
func (*Search)ExpandWildcards¶
func (r *Search) ExpandWildcards(expandwildcards ...expandwildcard.ExpandWildcard) *Search
ExpandWildcards The type of index that wildcard patterns can match.If the request can target data streams, this argument determines whetherwildcard expressions match hidden data streams.It supports comma-separated values such as `open,hidden`.API name: expand_wildcards
func (*Search)Explain¶
Explain If `true`, the request returns detailed information about score computationas part of a hit.API name: explain
func (*Search)Ext¶added inv8.9.0
func (r *Search) Ext(ext map[string]json.RawMessage) *Search
Ext Configuration of search extensions defined by Elasticsearch plugins.API name: ext
func (*Search)Fields¶added inv8.9.0
func (r *Search) Fields(fields ...types.FieldAndFormat) *Search
Fields An array of wildcard (`*`) field patterns.The request returns values for field names matching these patterns in the`hits.fields` property of the response.API name: fields
func (*Search)FilterPath¶added inv8.14.0
FilterPath Comma-separated list of filters in dot notation which reduce the responsereturned by Elasticsearch.API name: filter_path
func (*Search)ForceSyntheticSource¶added inv8.13.1
ForceSyntheticSource Should this request force synthetic _source?Use this to test if the mapping supports synthetic _source and to get a senseof the worst case performance.Fetches with this enabled will be slower the enabling synthetic sourcenatively in the index.API name: force_synthetic_source
func (*Search)From¶
From The starting document offset, which must be non-negative.By default, you cannot page through more than 10,000 hits using the `from`and `size` parameters.To page through more hits, use the `search_after` parameter.API name: from
func (*Search)Highlight¶added inv8.9.0
Highlight Specifies the highlighter to use for retrieving highlighted snippets from oneor more fields in your search results.API name: highlight
func (*Search)HttpRequest¶
HttpRequest returns the http.Request object built from thegiven parameters.
func (*Search)Human¶added inv8.14.0
Human When set to `true` will return statistics in a format suitable for humans.For example `"exists_time": "1h"` for humans and`"eixsts_time_in_millis": 3600000` for computers. When disabled the humanreadable values will be omitted. This makes sense for responses beingconsumedonly by machines.API name: human
func (*Search)IgnoreThrottled¶
IgnoreThrottled If `true`, concrete, expanded or aliased indices will be ignored when frozen.API name: ignore_throttled
func (*Search)IgnoreUnavailable¶
IgnoreUnavailable If `false`, the request returns an error if it targets a missing or closedindex.API name: ignore_unavailable
func (*Search)IncludeNamedQueriesScore¶added inv8.15.0
IncludeNamedQueriesScore If `true`, the response includes the score contribution from any namedqueries.
This functionality reruns each named query on every hit in a search response.Typically, this adds a small overhead to a request.However, using computationally expensive named queries on a large number ofhits may add significant overhead.API name: include_named_queries_score
func (*Search)Index¶
Index A comma-separated list of data streams, indices, and aliases to search.It supports wildcards (`*`).To search all data streams and indices, omit this parameter or use `*` or`_all`.API Name: index
func (*Search)IndicesBoost¶added inv8.9.0
IndicesBoost Boost the `_score` of documents from specified indices.The boost value is the factor by which scores are multiplied.A boost value greater than `1.0` increases the score.A boost value between `0` and `1.0` decreases the score.API name: indices_boost
func (*Search)Lenient¶
Lenient If `true`, format-based query failures (such as providing text to a numericfield) in the query string will be ignored.This parameter can be used only when the `q` query string parameter isspecified.API name: lenient
func (*Search)MaxConcurrentShardRequests¶
MaxConcurrentShardRequests The number of concurrent shard requests per node that the search runsconcurrently.This value should be used to limit the impact of the search on the cluster inorder to limit the number of concurrent shard requests.API name: max_concurrent_shard_requests
func (*Search)MinCompatibleShardNode¶
MinCompatibleShardNode The minimum version of the node that can handle the requestAny handling node with a lower version will fail the request.API name: min_compatible_shard_node
func (*Search)MinScore¶added inv8.9.0
MinScore The minimum `_score` for matching documents.Documents with a lower `_score` are not included in search results andresults collected by aggregations.API name: min_score
func (Search)Perform¶added inv8.7.0
Perform runs the http.Request through the provided transport and returns an http.Response.
func (*Search)Pit¶added inv8.9.0
func (r *Search) Pit(pit *types.PointInTimeReference) *Search
Pit Limit the search to a point in time (PIT).If you provide a PIT, you cannot specify an `<index>` in the request path.API name: pit
func (*Search)PostFilter¶added inv8.9.0
PostFilter Use the `post_filter` parameter to filter search results.The search hits are filtered after the aggregations are calculated.A post filter has no impact on the aggregation results.API name: post_filter
func (*Search)PreFilterShardSize¶
PreFilterShardSize A threshold that enforces a pre-filter roundtrip to prefilter search shardsbased on query rewriting if the number of shards the search request expandsto exceeds the threshold.This filter roundtrip can limit the number of shards significantly if forinstance a shard can not match any documents based on its rewrite method (ifdate filters are mandatory to match but the shard bounds and the query aredisjoint).When unspecified, the pre-filter phase is executed if any of these conditionsis 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.API name: pre_filter_shard_size
func (*Search)Preference¶
Preference The nodes and shards used for the search.By default, Elasticsearch selects from eligible nodes and shards usingadaptive 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 ifnot, select shards using the default method;* `_only_nodes:<node-id>,<node-id>` to run the search on only the specifiednodes 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 thespecified nodes are available, select shards from any available node usingthe default method;* `_prefer_nodes:<node-id>,<node-id>` to if possible, run the search on thespecified 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 routesearches with the same `<custom-string>` to the same shards in the sameorder.API name: preference
func (*Search)Pretty¶added inv8.14.0
Pretty If set to `true` the returned JSON will be "pretty-formatted". Only usethis option for debugging only.API name: pretty
func (*Search)Profile¶added inv8.9.0
Profile Set to `true` to return detailed timing information about the execution ofindividual components in a search request.NOTE: This is a debugging tool and adds significant overhead to searchexecution.API name: profile
func (*Search)Q¶
Q A query in the Lucene query string syntax.Query parameter searches do not support the full Elasticsearch Query DSL butare handy for testing.
IMPORTANT: This parameter overrides the query parameter in the request body.If both parameters are specified, documents matching the query request bodyparameter are not returned.API name: q
func (*Search)Rank¶added inv8.9.0
func (r *Search) Rank(rank *types.RankContainer) *Search
Rank The Reciprocal Rank Fusion (RRF) to use.API name: rank
func (*Search)Raw¶
Raw takes a json payload as input which is then passed to the http.RequestIf specified Raw takes precedence on Request method.
func (*Search)RequestCache¶
RequestCache If `true`, the caching of search results is enabled for requests where `size`is `0`.It defaults to index level settings.API name: request_cache
func (*Search)Rescore¶added inv8.9.0
Rescore Can be used to improve precision by reordering just the top (for example 100- 500) documents returned by the `query` and `post_filter` phases.API name: rescore
func (*Search)RestTotalHitsAsInt¶
RestTotalHitsAsInt Indicates whether `hits.total` should be rendered as an integer or an objectin the rest search response.API name: rest_total_hits_as_int
func (*Search)Retriever¶added inv8.14.0
func (r *Search) Retriever(retriever *types.RetrieverContainer) *Search
Retriever A retriever is a specification to describe top documents returned from asearch.A retriever replaces other elements of the search API that also return topdocuments such as `query` and `knn`.API name: retriever
func (*Search)Routing¶
Routing A custom value that is used to route operations to a specific shard.API name: routing
func (*Search)RuntimeMappings¶added inv8.9.0
func (r *Search) RuntimeMappings(runtimefieldstypes.RuntimeFields) *Search
RuntimeMappings One or more runtime fields in the search request.These fields take precedence over mapped fields with the same name.API name: runtime_mappings
func (*Search)ScriptFields¶added inv8.9.0
func (r *Search) ScriptFields(scriptfields map[string]types.ScriptField) *Search
ScriptFields Retrieve a script evaluation (based on different fields) for each hit.API name: script_fields
func (*Search)Scroll¶
Scroll The period to retain the search context for scrolling.By default, this value cannot exceed `1d` (24 hours).You can change this limit by using the `search.max_keep_alive` cluster-levelsetting.API name: scroll
func (*Search)SearchAfter¶added inv8.9.0
func (r *Search) SearchAfter(sortresults ...types.FieldValue) *Search
SearchAfter Used to retrieve the next page of hits using a set of sort values from theprevious page.API name: search_after
func (*Search)SearchType¶
func (r *Search) SearchType(searchtypesearchtype.SearchType) *Search
SearchType Indicates how distributed term frequencies are calculated for relevancescoring.API name: search_type
func (*Search)SeqNoPrimaryTerm¶
SeqNoPrimaryTerm If `true`, the request returns sequence number and primary term of the lastmodification of each hit.API name: seq_no_primary_term
func (*Search)Size¶
Size The number of hits to return, which must not be negative.By default, you cannot page through more than 10,000 hits using the `from`and `size` parameters.To page through more hits, use the `search_after` property.API name: size
func (*Search)Slice¶added inv8.9.0
func (r *Search) Slice(slice *types.SlicedScroll) *Search
Slice Split a scrolled search into multiple slices that can be consumedindependently.API name: slice
func (*Search)Sort¶
func (r *Search) Sort(sorts ...types.SortCombinations) *Search
Sort A comma-separated list of <field>:<direction> pairs.API name: sort
func (*Search)SourceExcludes_¶
SourceExcludes_ A comma-separated list of source fields to exclude from the response.You can also use this parameter to exclude fields from the subset specifiedin `_source_includes` query parameter.If the `_source` parameter is `false`, this parameter is ignored.API name: _source_excludes
func (*Search)SourceIncludes_¶
SourceIncludes_ A comma-separated list of source fields to include in the response.If this parameter is specified, only these source fields are returned.You can exclude fields from this subset using the `_source_excludes` queryparameter.If the `_source` parameter is `false`, this parameter is ignored.API name: _source_includes
func (*Search)Source_¶
func (r *Search) Source_(sourceconfigtypes.SourceConfig) *Search
Source_ The source fields that are returned for matching documents.These fields are returned in the `hits._source` property of the searchresponse.If the `stored_fields` property is specified, the `_source` property defaultsto `false`.Otherwise, it defaults to `true`.API name: _source
func (*Search)Stats¶
Stats The stats groups to associate with the search.Each group maintains a statistics aggregation for its associated searches.You can retrieve these stats using the indices stats API.API name: stats
func (*Search)StoredFields¶
StoredFields A comma-separated list of stored fields to return as part of a hit.If no fields are specified, no stored fields are included in the response.If this field is specified, the `_source` property defaults to `false`.You can pass `_source: true` to return both source fields and stored fieldsin the search response.API name: stored_fields
func (*Search)Suggest¶added inv8.9.0
Suggest Defines a suggester that provides similar looking terms based on a providedtext.API name: suggest
func (*Search)SuggestField¶
SuggestField The field to use for suggestions.API name: suggest_field
func (*Search)SuggestMode¶
func (r *Search) SuggestMode(suggestmodesuggestmode.SuggestMode) *Search
SuggestMode The suggest mode.This parameter can be used only when the `suggest_field` and `suggest_text`query string parameters are specified.API name: suggest_mode
func (*Search)SuggestSize¶
SuggestSize The number of suggestions to return.This parameter can be used only when the `suggest_field` and `suggest_text`query string parameters are specified.API name: suggest_size
func (*Search)SuggestText¶
SuggestText The source text for which the suggestions should be returned.This parameter can be used only when the `suggest_field` and `suggest_text`query string parameters are specified.API name: suggest_text
func (*Search)TerminateAfter¶
TerminateAfter The maximum number of documents to collect for each shard.If a query reaches this limit, Elasticsearch terminates the query early.Elasticsearch collects documents before sorting.
IMPORTANT: Use with caution.Elasticsearch applies this property to each shard handling the request.When possible, let Elasticsearch perform early termination automatically.Avoid specifying this property for requests that target data streams withbacking indices across multiple data tiers.
If set to `0` (default), the query does not terminate early.API name: terminate_after
func (*Search)Timeout¶
Timeout The period of time to wait for a response from each shard.If no response is received before the timeout expires, the request fails andreturns an error.Defaults to no timeout.API name: timeout
func (*Search)TrackScores¶
TrackScores If `true`, calculate and return document scores, even if the scores are notused for sorting.API name: track_scores
func (*Search)TrackTotalHits¶
TrackTotalHits Number of hits matching the query to count accurately.If `true`, the exact number of hits is returned at the cost of someperformance.If `false`, the response does not include the total number of hits matchingthe query.API name: track_total_hits