diff --git a/docs/HowTo/CustomParameters.md b/docs/HowTo/CustomParameters.md new file mode 100644 index 0000000000000000000000000000000000000000..1fed5b303d84e4bb8b6f9ab3da12d15aec94a326 --- /dev/null +++ b/docs/HowTo/CustomParameters.md @@ -0,0 +1,73 @@ +# How to set custom parameters to your search + +Elasticsearch supports number of custom parameters which can be added to your query. Detailed explanation of each parameter can be found at [official documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#_parameters_5) + +## Setting `timeout` parameter + +This option allows user to specify timeout for query execution in ["Time units"](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units). + +Following code + +```php +$search = new Search(); +$search->setTimeout('5s'); +``` + +would generate the query like this: +```json +{ + "timeout": "5s" +} +``` + +## Setting `from` and `size` parameters + +These parameters are usually used for pagination. + +Following code + +```php +$search = new Search(); +$search->setSize(25); +$search->setFrom(50); +``` + +would generate the query like this: +```json +{ + "size": 25, + "from": 50 +} +``` + +## Setting `terminate_after` parameter + +This parameter can limit how many documents can be fetched from shard before query execution is terminated. + +Following code + +```php +$search = new Search(); +$search->setTerminateAfter(1000); +``` + +would generate the query like this: +```json +{ + "terminate_after": 1000 +} +``` + +## Setting `search_type` and `request_cache` parameters + +These parameters are different from previous ones because they have to be passed not in query's body but as query string parameters. + +Following code + +```php +$search = new Search(); +$search->setSearchType('dfs_query_then_fetch'); +$search->setRequestCache(true); +``` + +would generate query string with `?search_type=dfs_query_then_fetch&request_cache=true`. \ No newline at end of file diff --git a/docs/index.md b/docs/index.md index 3936368102808cd710192a3ace4bc6253633a9ee..937fd46bf7b13860c32f34c4c147a4db4010a032 100644 --- a/docs/index.md +++ b/docs/index.md @@ -11,6 +11,7 @@ Everything starts from the `Search` object. We recommend first to take a look at ### How to - [How to Search](HowTo/HowToSearch.md) +- [How to set custom parameters to Search](HowTo/CustomParameters.md) - more coming soon.. [1]: https://github.com/elastic/elasticsearch-php