# Sorting by number of hits

**URL:** <https://discuss.elastic.co/t/sorting-by-number-of-hits/82784>\
**Category:** Elasticsearch\
**Created:** [April 18, 2017, 9:52pm UTC](https://discuss.elastic.co/t/sorting-by-number-of-hits/82784 "2017-04-18T21:52:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alopez](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@alopez](https://discuss.elastic.co/u/alopez)\
**Post date:** [April 18, 2017, 9:52pm UTC](https://discuss.elastic.co/t/sorting-by-number-of-hits/82784/1 "2017-04-18T21:52:25Z")

</div>

I'm fairly new to Elastic Search and am wondering if it's possible to sort the results by the number of hits each document has. Essentially, if i'm searching a string for the word "test" I need sort the results by the documents that have the string with the word "test" occuring the most. So far, this doesn't seem possible. Does anyone know how this can be done?

Thanks

---

<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:** [April 18, 2017, 10:05pm UTC](https://discuss.elastic.co/t/sorting-by-number-of-hits/82784/2 "2017-04-18T22:05:23Z")

</div>

Well the computed score is supposed to do that.  
By default elasticsearch sorts on score.

So all defaults should be good I think.

---

<div class="post-metadata">

**Author:** ![alopez](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@alopez](https://discuss.elastic.co/u/alopez)\
**Post date:** [April 18, 2017, 10:20pm UTC](https://discuss.elastic.co/t/sorting-by-number-of-hits/82784/3 "2017-04-18T22:20:57Z")

</div>

The computed score doesn't sort the way i need it. Probably didn't describe it well enough.

We have indexed large word documents into elastic search and have queries that search for words, phrases and wildcards in these word documents. We also use the highlighting feature to display the snippet of where these matches appear. What i need is to sort the results by the number of highlights for each word document. Is that possible?

---

<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:** [April 19, 2017, 6:44am UTC](https://discuss.elastic.co/t/sorting-by-number-of-hits/82784/4 "2017-04-19T06:44:21Z")

</div>

> [@alopez](#):
>
> What i need is to sort the results by the number of highlights for each word document. Is that possible?

I don't believe so.

---

<div class="post-metadata">

**Author:** ![alopez](https://avatars.discourse-cdn.com/v4/letter/a/97f17d/32.png) [@alopez](https://discuss.elastic.co/u/alopez)\
**Post date:** [April 19, 2017, 2:40pm UTC](https://discuss.elastic.co/t/sorting-by-number-of-hits/82784/5 "2017-04-19T14:40:15Z")

</div>

Ok. Thanks!

---

<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 17, 2017, 2:40pm UTC](https://discuss.elastic.co/t/sorting-by-number-of-hits/82784/6 "2017-05-17T14:40:58Z")

</div>

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