# Random N documents for a match query

**URL:** <https://discuss.elastic.co/t/random-n-documents-for-a-match-query/69203>\
**Category:** Elasticsearch\
**Created:** [December 15, 2016, 5:26pm UTC](https://discuss.elastic.co/t/random-n-documents-for-a-match-query/69203 "2016-12-15T17:26:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tyka](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@tyka](https://discuss.elastic.co/u/tyka)\
**Post date:** [December 15, 2016, 5:26pm UTC](https://discuss.elastic.co/t/random-n-documents-for-a-match-query/69203/1 "2016-12-15T17:26:48Z")

</div>

Hi there,

I need to get N random documents that have a given term in a string field.  
I tried something like the following, but it is still giving me the documents in asc order.

```
curl -XPOST 'localhost:9200/_search?pretty' -d '{
  "query": {
    "function_score" : {
      "query" : {"match": {"body": "happy"}},
      "random_score" : { "seed" : 1234 }
    }
  }
}'

```

any idea, how to get random N documents.

---

<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:** [January 12, 2017, 5:27pm UTC](https://discuss.elastic.co/t/random-n-documents-for-a-match-query/69203/2 "2017-01-12T17:27:05Z")

</div>

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