Class SearchRequestBody.Builder

All Implemented Interfaces:
WithJson<SearchRequestBody.Builder>, ObjectBuilder<SearchRequestBody>
Enclosing class:
SearchRequestBody

public static class SearchRequestBody.Builder extends WithJsonObjectBuilderBase<SearchRequestBody.Builder> implements ObjectBuilder<SearchRequestBody>
Builder for SearchRequestBody.
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • aggregations

      public final SearchRequestBody.Builder aggregations(Map<String,Aggregation> map)
      Defines the aggregations that are run as part of the search request.

      API name: aggregations

      Adds all entries of map to aggregations.

    • aggregations

      public final SearchRequestBody.Builder aggregations(String key, Aggregation value)
      Defines the aggregations that are run as part of the search request.

      API name: aggregations

      Adds an entry to aggregations.

    • aggregations

      public final SearchRequestBody.Builder aggregations(String key, AggregationVariant value)
      Defines the aggregations that are run as part of the search request.

      API name: aggregations

      Adds an entry to aggregations.

    • aggregations

      Defines the aggregations that are run as part of the search request.

      API name: aggregations

      Adds an entry to aggregations using a builder lambda.

    • collapse

      public final SearchRequestBody.Builder collapse(@Nullable FieldCollapse value)
      Collapses search results the values of the specified field.

      API name: collapse

    • collapse

      Collapses search results the values of the specified field.

      API name: collapse

    • explain

      public final SearchRequestBody.Builder explain(@Nullable Boolean value)
      If true, the request returns detailed information about score computation as part of a hit.

      API name: explain

    • ext

      public final SearchRequestBody.Builder ext(Map<String,JsonData> map)
      Configuration of search extensions defined by Elasticsearch plugins.

      API name: ext

      Adds all entries of map to ext.

    • ext

      public final SearchRequestBody.Builder ext(String key, JsonData value)
      Configuration of search extensions defined by Elasticsearch plugins.

      API name: ext

      Adds an entry to ext.

    • from

      public final SearchRequestBody.Builder from(@Nullable Integer value)
      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

    • highlight

      public final SearchRequestBody.Builder highlight(@Nullable Highlight value)
      Specifies the highlighter to use for retrieving highlighted snippets from one or more fields in your search results.

      API name: highlight

    • highlight

      Specifies the highlighter to use for retrieving highlighted snippets from one or more fields in your search results.

      API name: highlight

    • trackTotalHits

      public final SearchRequestBody.Builder trackTotalHits(@Nullable TrackHits 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.

      API name: track_total_hits

    • 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.

      API name: track_total_hits

    • indicesBoost

      public final SearchRequestBody.Builder indicesBoost(List<NamedValue<Double>> list)
      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

      Adds all elements of list to indicesBoost.

    • indicesBoost

      @SafeVarargs public final SearchRequestBody.Builder indicesBoost(NamedValue<Double> value, NamedValue<Double>... values)
      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

      Adds one or more values to indicesBoost.

    • docvalueFields

      public final SearchRequestBody.Builder docvalueFields(List<FieldAndFormat> list)
      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

      Adds all elements of list to docvalueFields.

    • docvalueFields

      public final SearchRequestBody.Builder docvalueFields(FieldAndFormat value, FieldAndFormat... values)
      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

      Adds one or more values to docvalueFields.

    • 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

      Adds a value to docvalueFields using a builder lambda.

    • knn

      public final SearchRequestBody.Builder knn(List<KnnSearch> list)
      The approximate kNN search to run.

      API name: knn

      Adds all elements of list to knn.

    • knn

      public final SearchRequestBody.Builder knn(KnnSearch value, KnnSearch... values)
      The approximate kNN search to run.

      API name: knn

      Adds one or more values to knn.

    • knn

      The approximate kNN search to run.

      API name: knn

      Adds a value to knn using a builder lambda.

    • rank

      public final SearchRequestBody.Builder rank(@Nullable Rank value)
      The Reciprocal Rank Fusion (RRF) to use.

      API name: rank

    • rank

      The Reciprocal Rank Fusion (RRF) to use.

      API name: rank

    • rank

      public final SearchRequestBody.Builder rank(RankVariant value)
      The Reciprocal Rank Fusion (RRF) to use.

      API name: rank

    • minScore

      public final SearchRequestBody.Builder minScore(@Nullable Double value)
      The minimum _score for matching documents. Documents with a lower _score are not included in search results or results collected by aggregations.

      API name: min_score

    • postFilter

      public final SearchRequestBody.Builder postFilter(@Nullable Query value)
      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

    • 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

    • postFilter

      public final SearchRequestBody.Builder postFilter(QueryVariant value)
      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

    • profile

      public final SearchRequestBody.Builder profile(@Nullable Boolean value)
      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.

      API name: profile

    • query

      public final SearchRequestBody.Builder query(@Nullable Query value)
      The search definition using the Query DSL.

      API name: query

    • query

      The search definition using the Query DSL.

      API name: query

    • query

      public final SearchRequestBody.Builder query(QueryVariant value)
      The search definition using the Query DSL.

      API name: query

    • rescore

      public final SearchRequestBody.Builder rescore(List<Rescore> list)
      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

      Adds all elements of list to rescore.

    • rescore

      public final SearchRequestBody.Builder rescore(Rescore value, Rescore... values)
      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

      Adds one or more values to rescore.

    • rescore

      public final SearchRequestBody.Builder rescore(RescoreVariant value, RescoreVariant... values)
      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

      Adds one or more values to rescore.

    • 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

      Adds a value to rescore using a builder lambda.

    • retriever

      public final SearchRequestBody.Builder retriever(@Nullable Retriever value)
      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.

      API name: retriever

    • 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.

      API name: retriever

    • retriever

      public final SearchRequestBody.Builder retriever(RetrieverVariant value)
      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.

      API name: retriever

    • scriptFields

      public final SearchRequestBody.Builder scriptFields(Map<String,ScriptField> map)
      Retrieve a script evaluation (based on different fields) for each hit.

      API name: script_fields

      Adds all entries of map to scriptFields.

    • scriptFields

      public final SearchRequestBody.Builder scriptFields(String key, ScriptField value)
      Retrieve a script evaluation (based on different fields) for each hit.

      API name: script_fields

      Adds an entry to scriptFields.

    • scriptFields

      Retrieve a script evaluation (based on different fields) for each hit.

      API name: script_fields

      Adds an entry to scriptFields using a builder lambda.

    • searchAfter

      public final SearchRequestBody.Builder searchAfter(List<FieldValue> list)
      Used to retrieve the next page of hits using a set of sort values from the previous page.

      API name: search_after

      Adds all elements of list to searchAfter.

    • searchAfter

      public final SearchRequestBody.Builder searchAfter(FieldValue value, FieldValue... values)
      Used to retrieve the next page of hits using a set of sort values from the previous page.

      API name: search_after

      Adds one or more values to searchAfter.

    • searchAfter

      public final SearchRequestBody.Builder searchAfter(String value, String... values)
      Used to retrieve the next page of hits using a set of sort values from the previous page.

      API name: search_after

      Adds one or more values to searchAfter.

    • searchAfter

      public final SearchRequestBody.Builder searchAfter(long value, long... values)
      Used to retrieve the next page of hits using a set of sort values from the previous page.

      API name: search_after

      Adds one or more values to searchAfter.

    • searchAfter

      public final SearchRequestBody.Builder searchAfter(double value, double... values)
      Used to retrieve the next page of hits using a set of sort values from the previous page.

      API name: search_after

      Adds one or more values to searchAfter.

    • searchAfter

      public final SearchRequestBody.Builder searchAfter(boolean value, boolean... values)
      Used to retrieve the next page of hits using a set of sort values from the previous page.

      API name: search_after

      Adds one or more values to searchAfter.

    • searchAfter

      Used to retrieve the next page of hits using a set of sort values from the previous page.

      API name: search_after

      Adds a value to searchAfter using a builder lambda.

    • size

      public final SearchRequestBody.Builder size(@Nullable Integer value)
      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

    • slice

      public final SearchRequestBody.Builder slice(@Nullable SlicedScroll value)
      Split a scrolled search into multiple slices that can be consumed independently.

      API name: slice

    • slice

      Split a scrolled search into multiple slices that can be consumed independently.

      API name: slice

    • sort

      public final SearchRequestBody.Builder sort(List<SortOptions> list)
      A comma-separated list of <field>:<direction> pairs.

      API name: sort

      Adds all elements of list to sort.

    • sort

      public final SearchRequestBody.Builder sort(SortOptions value, SortOptions... values)
      A comma-separated list of <field>:<direction> pairs.

      API name: sort

      Adds one or more values to sort.

    • sort

      A comma-separated list of <field>:<direction> pairs.

      API name: sort

      Adds a value to sort using a builder lambda.

    • source

      public final SearchRequestBody.Builder source(@Nullable SourceConfig value)
      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.

      API name: _source

    • 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.

      API name: _source

    • fields

      public final SearchRequestBody.Builder fields(List<FieldAndFormat> list)
      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

      Adds all elements of list to fields.

    • fields

      public final SearchRequestBody.Builder fields(FieldAndFormat value, FieldAndFormat... values)
      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

      Adds one or more values to fields.

    • 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

      Adds a value to fields using a builder lambda.

    • suggest

      public final SearchRequestBody.Builder suggest(@Nullable Suggester value)
      Defines a suggester that provides similar looking terms based on a provided text.

      API name: suggest

    • suggest

      Defines a suggester that provides similar looking terms based on a provided text.

      API name: suggest

    • terminateAfter

      public final SearchRequestBody.Builder terminateAfter(@Nullable Long value)
      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.

      API name: terminate_after

    • timeout

      public final SearchRequestBody.Builder timeout(@Nullable String value)
      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 final SearchRequestBody.Builder trackScores(@Nullable Boolean value)
      If true, calculate and return document scores, even if the scores are not used for sorting.

      API name: track_scores

    • version

      public final SearchRequestBody.Builder version(@Nullable Boolean value)
      If true, the request returns the document version as part of a hit.

      API name: version

    • seqNoPrimaryTerm

      public final SearchRequestBody.Builder seqNoPrimaryTerm(@Nullable Boolean value)
      If true, the request returns sequence number and primary term of the last modification of each hit.

      API name: seq_no_primary_term

    • storedFields

      public final SearchRequestBody.Builder storedFields(List<String> list)
      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.

      API name: stored_fields

      Adds all elements of list to storedFields.

    • storedFields

      public final SearchRequestBody.Builder storedFields(String value, String... values)
      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.

      API name: stored_fields

      Adds one or more values to storedFields.

    • pit

      public final SearchRequestBody.Builder pit(@Nullable PointInTimeReference value)
      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

    • 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

    • runtimeMappings

      public final SearchRequestBody.Builder runtimeMappings(Map<String,RuntimeField> map)
      One or more runtime fields in the search request. These fields take precedence over mapped fields with the same name.

      API name: runtime_mappings

      Adds all entries of map to runtimeMappings.

    • runtimeMappings

      public final SearchRequestBody.Builder runtimeMappings(String key, RuntimeField value)
      One or more runtime fields in the search request. These fields take precedence over mapped fields with the same name.

      API name: runtime_mappings

      Adds an entry to runtimeMappings.

    • 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

      Adds an entry to runtimeMappings using a builder lambda.

    • stats

      public final SearchRequestBody.Builder stats(List<String> list)
      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

      Adds all elements of list to stats.

    • stats

      public final SearchRequestBody.Builder stats(String value, String... values)
      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

      Adds one or more values to stats.

    • self

      protected SearchRequestBody.Builder self()
      Specified by:
      self in class WithJsonObjectBuilderBase<SearchRequestBody.Builder>
    • build

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