# Illegal\_argument\_exception when extract a random subset of an index

**URL:** <https://discuss.elastic.co/t/illegal-argument-exception-when-extract-a-random-subset-of-an-index/115995>\
**Category:** Elasticsearch\
**Created:** [January 18, 2018, 8:26am UTC](https://discuss.elastic.co/t/illegal-argument-exception-when-extract-a-random-subset-of-an-index/115995 "2018-01-18T08:26:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Hung](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@Mike\_Hung](https://discuss.elastic.co/u/Mike_Hung)\
**Post date:** [January 18, 2018, 8:26am UTC](https://discuss.elastic.co/t/illegal-argument-exception-when-extract-a-random-subset-of-an-index/115995/1 "2018-01-18T08:26:29Z")

</div>

Hello,

According to the Elasticsearch 5.6 [Reindex API document](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/docs-reindex.html#_extracting_a_random_subset_of_an_index).  
I have encountered the problem when running `_reindex` API as following command:

```
curl -XPOST 'localhost:9200/_reindex?pretty' -H 'Content-Type: application/json' -d'
{
  "size": 10,
  "source": {
    "index": "twitter",
    "query": {
      "function_score" : {
        "query" : { "match_all": {} },
        "random_score" : {}
      }
    },
    "sort": "_score"    
  },
  "dest": {
    "index": "random_twitter"
  }
}
'

```

Error message:

```
{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "Unsupported sort [{\n \"_score\" : {\n \"order\" : \"desc\"\n }\n}]"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "Unsupported sort [{\n \"_score\" : {\n \"order\" : \"desc\"\n }\n}]"
  },
  "status" : 400
}
```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 18, 2018, 9:39am UTC](https://discuss.elastic.co/t/illegal-argument-exception-when-extract-a-random-subset-of-an-index/115995/3 "2018-01-18T09:39:12Z")

</div>

I just tried this:

```auto
DELETE twitter
DELETE random_twitter
PUT twitter/doc/1
{
  "foo": "bar"
}
PUT random_twitter
POST _reindex
{
  "size": 10,
  "source": {
    "index": "twitter",
    "query": {
      "function_score" : {
        "query" : { "match_all": {} },
        "random_score" : {}
      }
    },
    "sort": "_score"    
  },
  "dest": {
    "index": "random_twitter"
  }
}

```

And it worked well. Tested on 5.6.5 and 6.1.1.

```auto
{
  "took": 33,
  "timed_out": false,
  "total": 10,
  "updated": 0,
  "created": 10,
  "deleted": 0,
  "batches": 1,
  "version_conflicts": 0,
  "noops": 0,
  "retries": {
    "bulk": 0,
    "search": 0
  },
  "throttled_millis": 0,
  "requests_per_second": -1,
  "throttled_until_millis": 0,
  "failures": []
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 15, 2018, 9:39am UTC](https://discuss.elastic.co/t/illegal-argument-exception-when-extract-a-random-subset-of-an-index/115995/4 "2018-02-15T09:39:51Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
