From eeb6602c985aacb09fb679db6b0557ba9b901c5f Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 10 Nov 2016 16:13:05 -0500 Subject: [PATCH] Document _reindex with random_score You can use `_reindex` and `random_score` to extract a random subset of an index but you have to be careful to sort by `_score` or it won't work. Closes #21432 --- docs/reference/docs/reindex.asciidoc | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/docs/reference/docs/reindex.asciidoc b/docs/reference/docs/reindex.asciidoc index 6279c3cae0f..f9025c378f6 100644 --- a/docs/reference/docs/reindex.asciidoc +++ b/docs/reference/docs/reindex.asciidoc @@ -935,3 +935,34 @@ GET metricbeat-2016.05.31-1/beat/1 The previous method can also be used in combination with <> to only load the existing data into the new index, but also rename fields if needed. + +[float] +=== Extracting a random subset of an index + +Reindex can be used to extract a random subset of an index for testing: + +[source,js] +---------------------------------------------------------------- +POST _reindex +{ + "size": 10, + "source": { + "index": "twitter", + "query": { + "function_score" : { + "query" : { "match_all": {} }, + "random_score" : {} + } + }, + "sort": "_score" <1> + }, + "dest": { + "index": "random_twitter" + } +} +---------------------------------------------------------------- +// CONSOLE +// TEST[setup:big_twitter] + +<1> Reindex defaults to sorting by `_doc` so `random_score` won't have any +effect unless you override the sort to `_score`.