diff --git a/_aggregations/bucket/index.md b/_aggregations/bucket/index.md index e1a02b890db..595eb9b3680 100644 --- a/_aggregations/bucket/index.md +++ b/_aggregations/bucket/index.md @@ -39,8 +39,9 @@ OpenSearch supports the following bucket aggregations: - [Multi-terms]({{site.url}}{{site.baseurl}}/aggregations/bucket/multi-terms/) - [Nested]({{site.url}}{{site.baseurl}}/aggregations/bucket/nested/) - [Range]({{site.url}}{{site.baseurl}}/aggregations/bucket/range/) +- [Random sort]({{site.url}}{{site.baseurl}}/aggregations/bucket/random-sort/) - [Reverse nested]({{site.url}}{{site.baseurl}}/aggregations/bucket/reverse-nested/) - [Sampler]({{site.url}}{{site.baseurl}}/aggregations/bucket/sampler/) - [Significant terms]({{site.url}}{{site.baseurl}}/aggregations/bucket/significant-terms/) - [Significant text]({{site.url}}{{site.baseurl}}/aggregations/bucket/significant-text/) -- [Terms]({{site.url}}{{site.baseurl}}/aggregations/bucket/terms/) \ No newline at end of file +- [Terms]({{site.url}}{{site.baseurl}}/aggregations/bucket/terms/) diff --git a/_aggregations/bucket/random-sort.md b/_aggregations/bucket/random-sort.md new file mode 100644 index 00000000000..59b3567a02f --- /dev/null +++ b/_aggregations/bucket/random-sort.md @@ -0,0 +1,100 @@ +--- +layout: default +title: Random sort +parent: Bucket aggregations +nav_order: 165 +--- + +# Random sort + +The random sort plugin allows you to sort search results randomly. This can be useful for implementing features like randomized search results or A/B testing. + +## Installation + +The random sort plugin is not installed by default. To install it, use the plugin install command: + +```bash +bin/opensearch-plugin install random-sort +``` + +## Usage + +To use random sorting, add a `sort` parameter to your search request with the following syntax: + +```json +{ + "sort": [ + { + "_script": { + "type": "number", + "script": { + "lang": "randomsort", + "source": "random_sort" + }, + "order": "asc" + } + } + ] +} +``` + +You can optionally provide a `seed` parameter to ensure consistent randomization across requests: + +```json +{ + "sort": [ + { + "_script": { + "type": "number", + "script": { + "lang": "randomsort", + "source": "random_sort", + "params": { + "seed": 1234 + } + }, + "order": "asc" + } + } + ] +} +``` + +## Example + +Here's a complete example of a search request using random sort: + +```json +GET /my-index/_search +{ + "size": 10, + "query": { + "match_all": {} + }, + "sort": [ + { + "_script": { + "type": "number", + "script": { + "lang": "randomsort", + "source": "random_sort", + "params": { + "seed": 1234 + } + }, + "order": "asc" + } + } + ] +} +``` + +This will return 10 documents from `my-index`, sorted in a random order. The randomization will be consistent across requests as long as the same seed is used. + +## How it works + +The random sort plugin implements a custom script engine that generates a random number for each document. This number is then used as the sort key. When a seed is provided, it ensures that the same sequence of random numbers is generated for each document across multiple requests. + +## Performance considerations + +While random sorting can be useful, it may impact query performance, especially on large datasets. The plugin has to generate a random number for each matching document, which can be computationally expensive. Use this feature judiciously and consider its impact on your overall system performance. \ No newline at end of file diff --git a/_plugins/search-history.md b/_plugins/search-history.md new file mode 100644 index 00000000000..a253ed0db74 --- /dev/null +++ b/_plugins/search-history.md @@ -0,0 +1,68 @@ +--- +layout: default +title: Search history +nav_order: 140 +has_children: false +parent: Plugins +--- + +# Search history plugin + +The search history plugin allows you to save and retrieve a user's search history in OpenSearch. This can be useful for enabling features like recent searches or personalized search suggestions. + +## Installation + +The search history plugin is included with OpenSearch by default. No additional installation steps are required. + +## Configuration + +The plugin has two main configuration settings that can be adjusted in `opensearch.yml`: + +```yaml +search.history.max_size: 100 # Maximum number of searches to store per user +search.history.retention_days: 30 # Number of days to retain search history +``` + +## Usage + +The plugin provides REST APIs for saving and retrieving search history: + +### Save search history + +``` +POST /_search_history +{ + "query": "my search query", + "indices": ["index1", "index2"], + "hit_count": 53 +} +``` + +This saves the search query, indices searched, and number of hits to the user's search history. + +### Retrieve search history + +``` +GET /_search_history?from=0&size=20 +``` + +This retrieves the user's search history, paginated by the `from` and `size` parameters. + +### Delete search history + +``` +DELETE /_search_history?query=my+search+query +``` + +This deletes matching entries from the user's search history. + +## Security + +The plugin uses the authenticated user's ID to segregate and secure search history data. Users can only access their own search history. + +## Limitations + +- The plugin currently stores search history data in-memory and is not designed for production use with large volumes of users/searches. +- Search history is not persisted across cluster restarts. + +For more details on the plugin implementation, see the [SearchHistoryPlugin](https://github.com/opensearch-project/OpenSearch/blob/main/plugins/search-history/src/main/java/org/opensearch/plugin/searchhistory/SearchHistoryPlugin.java) and [SearchHistoryService](https://github.com/opensearch-project/OpenSearch/blob/main/plugins/search-history/src/main/java/org/opensearch/plugin/searchhistory/SearchHistoryService.java) classes. \ No newline at end of file