# Search latency comparison of using \_seq\_no vs a keyword field in random\_score function

**URL:** <https://discuss.elastic.co/t/search-latency-comparison-of-using-seq-no-vs-a-keyword-field-in-random-score-function/330381>\
**Category:** Elasticsearch\
**Created:** [April 20, 2023, 10:31am UTC](https://discuss.elastic.co/t/search-latency-comparison-of-using-seq-no-vs-a-keyword-field-in-random-score-function/330381 "2023-04-20T10:31:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shekimod](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shekimod/32/120036_2.png) [@shekimod](https://discuss.elastic.co/u/shekimod)\
**Post date:** [April 20, 2023, 10:31am UTC](https://discuss.elastic.co/t/search-latency-comparison-of-using-seq-no-vs-a-keyword-field-in-random-score-function/330381/1 "2023-04-20T10:31:59Z")

</div>

Hi all,

We are using random\_score function with seed as `System.nanoTime()` and field as one of the keyword fields in the index for a use-case of returning random results from the index with pagination support. We are observing huge search latencies (1000-4000ms range) when the number of documents that are matched are high (\>10000) (we use filters etc. but we have to return these documents). I ran an adhoc test and observed that using `_seq_no` as field has much better search latency (80-130ms range).

From [ES documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#function-random), it is mentioned:

`A good default choice might be to use the _seq_no field, whose only drawback is that scores will change if the document is updated since update operations also update the value of the _seq_no field.`

We can accept the `_seq_no` value changes when the document gets updated. I wanted to understand why using the `_seq_no` field is efficient compared to using a keyword field in the index. Could anyone share some light on it? I could not find any documentation related to why this could happen.

---

<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:** [May 18, 2023, 10:32am UTC](https://discuss.elastic.co/t/search-latency-comparison-of-using-seq-no-vs-a-keyword-field-in-random-score-function/330381/2 "2023-05-18T10:32:25Z")

</div>

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