Class SearchRequest.Builder

java.lang.Object
co.elastic.clients.elasticsearch._core.SearchRequest.Builder
All Implemented Interfaces:
ObjectBuilder<SearchRequest>
Enclosing class:
SearchRequest

public static class SearchRequest.Builder
extends java.lang.Object
implements ObjectBuilder<SearchRequest>
Builder for SearchRequest.
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • index

      public SearchRequest.Builder index​(@Nullable java.util.List<java.lang.String> value)
      A comma-separated list of index names to search; use _all or empty string to perform the operation on all indices

      API name: index

    • index

      public SearchRequest.Builder index​(java.lang.String... value)
      A comma-separated list of index names to search; use _all or empty string to perform the operation on all indices

      API name: index

    • addIndex

      public SearchRequest.Builder addIndex​(java.lang.String value)
      Add a value to index(List), creating the list if needed.
    • type

      public SearchRequest.Builder type​(@Nullable java.util.List<java.lang.String> value)
      A comma-separated list of document types to search; leave empty to perform the operation on all types

      API name: type

    • type

      public SearchRequest.Builder type​(java.lang.String... value)
      A comma-separated list of document types to search; leave empty to perform the operation on all types

      API name: type

    • addType

      public SearchRequest.Builder addType​(java.lang.String value)
      Add a value to type(List), creating the list if needed.
    • allowNoIndices

      public SearchRequest.Builder allowNoIndices​(@Nullable java.lang.Boolean value)
      Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes _all string or when no indices have been specified)

      API name: allow_no_indices

    • allowPartialSearchResults

      public SearchRequest.Builder allowPartialSearchResults​(@Nullable java.lang.Boolean value)
      Indicate if an error should be returned if there is a partial search failure or timeout

      API name: allow_partial_search_results

    • analyzer

      public SearchRequest.Builder analyzer​(@Nullable java.lang.String value)
      The analyzer to use for the query string

      API name: analyzer

    • analyzeWildcard

      public SearchRequest.Builder analyzeWildcard​(@Nullable java.lang.Boolean value)
      Specify whether wildcard and prefix queries should be analyzed (default: false)

      API name: analyze_wildcard

    • batchedReduceSize

      public SearchRequest.Builder batchedReduceSize​(@Nullable java.lang.Long value)
      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.

      API name: batched_reduce_size

    • ccsMinimizeRoundtrips

      public SearchRequest.Builder ccsMinimizeRoundtrips​(@Nullable java.lang.Boolean value)
      Indicates whether network round-trips should be minimized as part of cross-cluster search requests execution

      API name: ccs_minimize_roundtrips

    • defaultOperator

      public SearchRequest.Builder defaultOperator​(@Nullable DefaultOperator value)
      The default operator for query string query (AND or OR)

      API name: default_operator

    • df

      public SearchRequest.Builder df​(@Nullable java.lang.String value)
      The field to use as default where no field prefix is given in the query string

      API name: df

    • expandWildcards

      public SearchRequest.Builder expandWildcards​(@Nullable java.util.List<ExpandWildcardOptions> value)
      Whether to expand wildcard expression to concrete indices that are open, closed or both.

      API name: expand_wildcards

    • expandWildcards

      public SearchRequest.Builder expandWildcards​(ExpandWildcardOptions... value)
      Whether to expand wildcard expression to concrete indices that are open, closed or both.

      API name: expand_wildcards

    • addExpandWildcards

      public SearchRequest.Builder addExpandWildcards​(ExpandWildcardOptions value)
      Add a value to expandWildcards(List), creating the list if needed.
    • ignoreThrottled

      public SearchRequest.Builder ignoreThrottled​(@Nullable java.lang.Boolean value)
      Whether specified concrete, expanded or aliased indices should be ignored when throttled

      API name: ignore_throttled

    • ignoreUnavailable

      public SearchRequest.Builder ignoreUnavailable​(@Nullable java.lang.Boolean value)
      Whether specified concrete indices should be ignored when unavailable (missing or closed)

      API name: ignore_unavailable

    • lenient

      public SearchRequest.Builder lenient​(@Nullable java.lang.Boolean value)
      Specify whether format-based query failures (such as providing text to a numeric field) should be ignored

      API name: lenient

    • maxConcurrentShardRequests

      public SearchRequest.Builder maxConcurrentShardRequests​(@Nullable java.lang.Long value)
      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

      API name: max_concurrent_shard_requests

    • minCompatibleShardNode

      public SearchRequest.Builder minCompatibleShardNode​(@Nullable java.lang.String value)
      The minimum compatible version that all shards involved in search should have for this request to be successful

      API name: min_compatible_shard_node

    • preference

      public SearchRequest.Builder preference​(@Nullable java.lang.String value)
      Specify the node or shard the operation should be performed on (default: random)

      API name: preference

    • preFilterShardSize

      public SearchRequest.Builder preFilterShardSize​(@Nullable java.lang.Long value)
      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 ie. if date filters are mandatory to match but the shard bounds and the query are disjoint.

      API name: pre_filter_shard_size

    • requestCache

      public SearchRequest.Builder requestCache​(@Nullable java.lang.Boolean value)
      Specify if request cache should be used for this request or not, defaults to index level setting

      API name: request_cache

    • routing

      public SearchRequest.Builder routing​(@Nullable java.lang.String value)
      A comma-separated list of specific routing values

      API name: routing

    • scroll

      public SearchRequest.Builder scroll​(@Nullable java.lang.String value)
      Specify how long a consistent view of the index should be maintained for scrolled search

      API name: scroll

    • searchType

      public SearchRequest.Builder searchType​(@Nullable SearchType value)
      Search operation type

      API name: search_type

    • suggestField

      public SearchRequest.Builder suggestField​(@Nullable java.lang.String value)
      Specifies which field to use for suggestions.

      API name: suggest_field

    • suggestMode

      public SearchRequest.Builder suggestMode​(@Nullable SuggestMode value)
      Specify suggest mode

      API name: suggest_mode

    • suggestSize

      public SearchRequest.Builder suggestSize​(@Nullable java.lang.Long value)
      How many suggestions to return in response

      API name: suggest_size

    • suggestText

      public SearchRequest.Builder suggestText​(@Nullable java.lang.String value)
      The source text for which the suggestions should be returned.

      API name: suggest_text

    • typedKeys

      public SearchRequest.Builder typedKeys​(@Nullable java.lang.Boolean value)
      Specify whether aggregation and suggester names should be prefixed by their respective types in the response

      API name: typed_keys

    • sourceExcludes

      public SearchRequest.Builder sourceExcludes​(@Nullable java.util.List<java.lang.String> value)
      A list of fields to exclude from the returned _source field

      API name: _source_excludes

    • sourceExcludes

      public SearchRequest.Builder sourceExcludes​(java.lang.String... value)
      A list of fields to exclude from the returned _source field

      API name: _source_excludes

    • addSourceExcludes

      public SearchRequest.Builder addSourceExcludes​(java.lang.String value)
      Add a value to sourceExcludes(List), creating the list if needed.
    • sourceIncludes

      public SearchRequest.Builder sourceIncludes​(@Nullable java.util.List<java.lang.String> value)
      A list of fields to extract and return from the _source field

      API name: _source_includes

    • sourceIncludes

      public SearchRequest.Builder sourceIncludes​(java.lang.String... value)
      A list of fields to extract and return from the _source field

      API name: _source_includes

    • addSourceIncludes

      public SearchRequest.Builder addSourceIncludes​(java.lang.String value)
      Add a value to sourceIncludes(List), creating the list if needed.
    • q

      public SearchRequest.Builder q​(@Nullable java.lang.String value)
      Query in the Lucene query string syntax

      API name: q

    • aggs

      public SearchRequest.Builder aggs​(@Nullable java.util.Map<java.lang.String,​Aggregation> value)
      API name: aggs
    • putAggs

      public SearchRequest.Builder putAggs​(java.lang.String key, Aggregation value)
      Add a key/value to aggs(Map), creating the map if needed.
    • aggs

      public SearchRequest.Builder aggs​(java.lang.String key, java.util.function.Function<Aggregation.Builder,​ObjectBuilder<Aggregation>> fn)
      Set aggs(Map) to a singleton map.
    • putAggs

      public SearchRequest.Builder putAggs​(java.lang.String key, java.util.function.Function<Aggregation.Builder,​ObjectBuilder<Aggregation>> fn)
      Add a key/value to aggs(Map), creating the map if needed.
    • aggregations

      public SearchRequest.Builder aggregations​(@Nullable java.util.Map<java.lang.String,​Aggregation> value)
      API name: aggregations
    • putAggregations

      public SearchRequest.Builder putAggregations​(java.lang.String key, Aggregation value)
      Add a key/value to aggregations(Map), creating the map if needed.
    • aggregations

      public SearchRequest.Builder aggregations​(java.lang.String key, java.util.function.Function<Aggregation.Builder,​ObjectBuilder<Aggregation>> fn)
      Set aggregations(Map) to a singleton map.
    • putAggregations

      public SearchRequest.Builder putAggregations​(java.lang.String key, java.util.function.Function<Aggregation.Builder,​ObjectBuilder<Aggregation>> fn)
      Add a key/value to aggregations(Map), creating the map if needed.
    • collapse

      public SearchRequest.Builder collapse​(@Nullable FieldCollapse value)
      API name: collapse
    • collapse

      public SearchRequest.Builder collapse​(java.util.function.Function<FieldCollapse.Builder,​ObjectBuilder<FieldCollapse>> fn)
      API name: collapse
    • explain

      public SearchRequest.Builder explain​(@Nullable java.lang.Boolean value)
      If true, returns detailed information about score computation as part of a hit.

      API name: explain

    • from

      public SearchRequest.Builder from​(@Nullable java.lang.Integer value)
      Starting document offset. 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

    • highlight

      public SearchRequest.Builder highlight​(@Nullable Highlight value)
      API name: highlight
    • highlight

      public SearchRequest.Builder highlight​(java.util.function.Function<Highlight.Builder,​ObjectBuilder<Highlight>> fn)
      API name: highlight
    • trackTotalHits

      public SearchRequest.Builder trackTotalHits​(@Nullable jakarta.json.JsonValue value)
      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. Defaults to 10,000 hits.

      API name: track_total_hits

    • indicesBoost

      public SearchRequest.Builder indicesBoost​(@Nullable java.util.List<java.util.Map<java.lang.String,​java.lang.Double>> value)
      Boosts the _score of documents from specified indices.

      API name: indices_boost

    • indicesBoost

      public SearchRequest.Builder indicesBoost​(java.util.Map<java.lang.String,​java.lang.Double>... value)
      Boosts the _score of documents from specified indices.

      API name: indices_boost

    • addIndicesBoost

      public SearchRequest.Builder addIndicesBoost​(java.util.Map<java.lang.String,​java.lang.Double> value)
      Add a value to indicesBoost(List), creating the list if needed.
    • docvalueFields

      public SearchRequest.Builder docvalueFields​(@Nullable jakarta.json.JsonValue value)
      Array of wildcard (*) patterns. The request returns doc values for field names matching these patterns in the hits.fields property of the response.

      API name: docvalue_fields

    • minScore

      public SearchRequest.Builder minScore​(@Nullable java.lang.Double value)
      Minimum _score for matching documents. Documents with a lower _score are not included in the search results.

      API name: min_score

    • postFilter

      public SearchRequest.Builder postFilter​(@Nullable Query value)
      API name: post_filter
    • postFilter

      public SearchRequest.Builder postFilter​(java.util.function.Function<Query.Builder,​ObjectBuilder<Query>> fn)
      API name: post_filter
    • profile

      public SearchRequest.Builder profile​(@Nullable java.lang.Boolean value)
      API name: profile
    • query

      public SearchRequest.Builder query​(@Nullable Query value)
      Defines the search definition using the Query DSL.

      API name: query

    • query

      public SearchRequest.Builder query​(java.util.function.Function<Query.Builder,​ObjectBuilder<Query>> fn)
      Defines the search definition using the Query DSL.

      API name: query

    • rescore

      public SearchRequest.Builder rescore​(@Nullable java.util.List<Rescore> value)
      API name: rescore
    • rescore

      public SearchRequest.Builder rescore​(Rescore... value)
      API name: rescore
    • addRescore

      public SearchRequest.Builder addRescore​(Rescore value)
      Add a value to rescore(List), creating the list if needed.
    • rescore

      public SearchRequest.Builder rescore​(java.util.function.Function<Rescore.Builder,​ObjectBuilder<Rescore>> fn)
      Set rescore(List) to a singleton list.
    • addRescore

      public SearchRequest.Builder addRescore​(java.util.function.Function<Rescore.Builder,​ObjectBuilder<Rescore>> fn)
      Add a value to rescore(List), creating the list if needed.
    • scriptFields

      public SearchRequest.Builder scriptFields​(@Nullable java.util.Map<java.lang.String,​ScriptField> value)
      Retrieve a script evaluation (based on different fields) for each hit.

      API name: script_fields

    • putScriptFields

      public SearchRequest.Builder putScriptFields​(java.lang.String key, ScriptField value)
      Add a key/value to scriptFields(Map), creating the map if needed.
    • scriptFields

      public SearchRequest.Builder scriptFields​(java.lang.String key, java.util.function.Function<ScriptField.Builder,​ObjectBuilder<ScriptField>> fn)
      Set scriptFields(Map) to a singleton map.
    • putScriptFields

      public SearchRequest.Builder putScriptFields​(java.lang.String key, java.util.function.Function<ScriptField.Builder,​ObjectBuilder<ScriptField>> fn)
      Add a key/value to scriptFields(Map), creating the map if needed.
    • searchAfter

      public SearchRequest.Builder searchAfter​(@Nullable java.util.List<java.lang.String> value)
      API name: search_after
    • searchAfter

      public SearchRequest.Builder searchAfter​(java.lang.String... value)
      API name: search_after
    • addSearchAfter

      public SearchRequest.Builder addSearchAfter​(java.lang.String value)
      Add a value to searchAfter(List), creating the list if needed.
    • size

      public SearchRequest.Builder size​(@Nullable java.lang.Integer value)
      The number of hits to return. 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: size

    • slice

      public SearchRequest.Builder slice​(@Nullable SlicedScroll value)
      API name: slice
    • slice

      public SearchRequest.Builder slice​(java.util.function.Function<SlicedScroll.Builder,​ObjectBuilder<SlicedScroll>> fn)
      API name: slice
    • sort

      public SearchRequest.Builder sort​(@Nullable java.util.List<jakarta.json.JsonValue> value)
      API name: sort
    • sort

      public SearchRequest.Builder sort​(jakarta.json.JsonValue... value)
      API name: sort
    • addSort

      public SearchRequest.Builder addSort​(jakarta.json.JsonValue value)
      Add a value to sort(List), creating the list if needed.
    • source

      public SearchRequest.Builder source​(@Nullable jakarta.json.JsonValue value)
      Indicates which source fields are returned for matching documents. These fields are returned in the hits._source property of the search response.

      API name: _source

    • fields

      public SearchRequest.Builder fields​(@Nullable java.util.List<jakarta.json.JsonValue> value)
      Array of wildcard (*) patterns. The request returns values for field names matching these patterns in the hits.fields property of the response.

      API name: fields

    • fields

      public SearchRequest.Builder fields​(jakarta.json.JsonValue... value)
      Array of wildcard (*) patterns. The request returns values for field names matching these patterns in the hits.fields property of the response.

      API name: fields

    • addFields

      public SearchRequest.Builder addFields​(jakarta.json.JsonValue value)
      Add a value to fields(List), creating the list if needed.
    • suggest

      public SearchRequest.Builder suggest​(@Nullable jakarta.json.JsonValue value)
      API name: suggest
    • terminateAfter

      public SearchRequest.Builder terminateAfter​(@Nullable java.lang.Long value)
      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. Defaults to 0, which does not terminate query execution early.

      API name: terminate_after

    • timeout

      public SearchRequest.Builder timeout​(@Nullable java.lang.String value)
      Specifies 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.

      API name: timeout

    • trackScores

      public SearchRequest.Builder trackScores​(@Nullable java.lang.Boolean value)
      If true, calculate and return document scores, even if the scores are not used for sorting.

      API name: track_scores

    • version

      public SearchRequest.Builder version​(@Nullable java.lang.Boolean value)
      If true, returns document version as part of a hit.

      API name: version

    • seqNoPrimaryTerm

      public SearchRequest.Builder seqNoPrimaryTerm​(@Nullable java.lang.Boolean value)
      If true, returns sequence number and primary term of the last modification of each hit. See Optimistic concurrency control.

      API name: seq_no_primary_term

    • storedFields

      public SearchRequest.Builder storedFields​(@Nullable java.util.List<java.lang.String> value)
      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 parameter defaults to false. You can pass _source: true to return both source fields and stored fields in the search response.

      API name: stored_fields

    • storedFields

      public SearchRequest.Builder storedFields​(java.lang.String... value)
      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 parameter defaults to false. You can pass _source: true to return both source fields and stored fields in the search response.

      API name: stored_fields

    • addStoredFields

      public SearchRequest.Builder addStoredFields​(java.lang.String value)
      Add a value to storedFields(List), creating the list if needed.
    • pit

      public SearchRequest.Builder pit​(@Nullable PointInTimeReference value)
      Limits 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

    • pit

      public SearchRequest.Builder pit​(java.util.function.Function<PointInTimeReference.Builder,​ObjectBuilder<PointInTimeReference>> fn)
      Limits 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

    • runtimeMappings

      public SearchRequest.Builder runtimeMappings​(@Nullable java.util.Map<java.lang.String,​RuntimeField> value)
      Defines one or more runtime fields in the search request. These fields take precedence over mapped fields with the same name.

      API name: runtime_mappings

    • putRuntimeMappings

      public SearchRequest.Builder putRuntimeMappings​(java.lang.String key, RuntimeField value)
      Add a key/value to runtimeMappings(Map), creating the map if needed.
    • runtimeMappings

      public SearchRequest.Builder runtimeMappings​(java.lang.String key, java.util.function.Function<RuntimeField.Builder,​ObjectBuilder<RuntimeField>> fn)
      Set runtimeMappings(Map) to a singleton map.
    • putRuntimeMappings

      public SearchRequest.Builder putRuntimeMappings​(java.lang.String key, java.util.function.Function<RuntimeField.Builder,​ObjectBuilder<RuntimeField>> fn)
      Add a key/value to runtimeMappings(Map), creating the map if needed.
    • stats

      public SearchRequest.Builder stats​(@Nullable java.util.List<java.lang.String> value)
      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

    • stats

      public SearchRequest.Builder stats​(java.lang.String... value)
      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

    • addStats

      public SearchRequest.Builder addStats​(java.lang.String value)
      Add a value to stats(List), creating the list if needed.
    • build

      public SearchRequest build()
      Builds a SearchRequest.
      Specified by:
      build in interface ObjectBuilder<SearchRequest>
      Throws:
      java.lang.NullPointerException - if some of the required fields are null.