<commit_before>--
:api: search
:request: SearchRequest
:response: SearchResponse
--

[id="{upid}-{api}"]
=== Search API

[id="{upid}-{api}-request"]
==== Search Request

The +{request}+ is used for any operation that has to do with searching
documents, aggregations, suggestions and also offers ways of requesting
highlighting on the resulting documents.

In its most basic form, we can add a query to the request:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-basic]
--------------------------------------------------

<1> Creates the `SeachRequest`. Without arguments this runs against all indices.
<2> Most search parameters are added to the `SearchSourceBuilder`. It offers setters for everything that goes into the search request body.
<3> Add a `match_all` query to the `SearchSourceBuilder`.
<4> Add the `SearchSourceBuilder` to the `SeachRequest`.

[id="{upid}-{api}-request-optional"]
===== Optional arguments

Let's first look at some of the optional arguments of a +{request}+:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-indices]
--------------------------------------------------
<1> Restricts the request to an index

There are a couple of other interesting optional parameters:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-routing]
--------------------------------------------------
<1> Set a routing parameter

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-indicesOptions]
--------------------------------------------------<commit_msg>[DOCS] Fixed "SeachRequest" -> "SearchRequest" typo in HLRC docs (#52144)<commit_after>--
:api: search
:request: SearchRequest
:response: SearchResponse
--

[id="{upid}-{api}"]
=== Search API

[id="{upid}-{api}-request"]
==== Search Request

The +{request}+ is used for any operation that has to do with searching
documents, aggregations, suggestions and also offers ways of requesting
highlighting on the resulting documents.

In its most basic form, we can add a query to the request:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-basic]
--------------------------------------------------

<1> Creates the `SearchRequest`. Without arguments this runs against all indices.
<2> Most search parameters are added to the `SearchSourceBuilder`. It offers setters for everything that goes into the search request body.
<3> Add a `match_all` query to the `SearchSourceBuilder`.
<4> Add the `SearchSourceBuilder` to the `SearchRequest`.

[id="{upid}-{api}-request-optional"]
===== Optional arguments

Let's first look at some of the optional arguments of a +{request}+:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-indices]
--------------------------------------------------
<1> Restricts the request to an index

There are a couple of other interesting optional parameters:

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-routing]
--------------------------------------------------
<1> Set a routing parameter

["source","java",subs="attributes,callouts,macros"]
--------------------------------------------------
include-tagged::{doc-tests-file}[{api}-request-indicesOptions]
--------------------------------------------------
{'fraction_non_alphanumeric': 0.32221638655462187, 'fraction_numerical': 0.004464285714285714, 'mean_word_length': 2.124692370795734, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6712692', 'n_tokens_mistral': 920, 'n_tokens_neox': 895, 'n_words': 296}