# Sort by \_version field

**URL:** <https://discuss.elastic.co/t/sort-by--version-field/8169>\
**Category:** Elasticsearch\
**Created:** [June 20, 2012, 2:28pm UTC](https://discuss.elastic.co/t/sort-by--version-field/8169 "2012-06-20T14:28:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_2](https://avatars.discourse-cdn.com/v4/letter/g/50afbb/32.png) [@Greg\_2](https://discuss.elastic.co/u/Greg_2)\
**Post date:** [June 20, 2012, 2:28pm UTC](https://discuss.elastic.co/t/sort-by--version-field/8169/1 "2012-06-20T14:28:16Z")

</div>

Hi,

i must sort the documents by the version number ("\_version"- field).  
How can I do that?

Thanks.

Greg

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [June 21, 2012, 7:27am UTC](https://discuss.elastic.co/t/sort-by--version-field/8169/2 "2012-06-21T07:27:47Z")

</div>

There is no way to sort on the \_version field. Why do you need it? Can you  
explain the use case a bit?

On Wed, Jun 20, 2012 at 4:28 PM, Greg [linuxzwerg@googlemail.com](mailto:linuxzwerg@googlemail.com) wrote:

> Hi,
> 
> i must sort the documents by the version number ("\_version"- field).  
> How can I do that?
> 
> Thanks.
> 
> Greg

---

<div class="post-metadata">

**Author:** ![Greg\_2](https://avatars.discourse-cdn.com/v4/letter/g/50afbb/32.png) [@Greg\_2](https://discuss.elastic.co/u/Greg_2)\
**Post date:** [June 21, 2012, 8:35am UTC](https://discuss.elastic.co/t/sort-by--version-field/8169/3 "2012-06-21T08:35:37Z")

</div>

Hi,

i want to create search term statistics. If new search occurs then i create  
a document with id like a term. If document exists, version will increased.  
And then i want to select 10 most searched terms.

Have you any idea how I could do it differently?

Thanks.  
Greg

Am Donnerstag, 21. Juni 2012 09:27:47 UTC+2 schrieb kimchy:

> There is no way to sort on the \_version field. Why do you need it? Can you  
> explain the use case a bit?
> 
> On Wed, Jun 20, 2012 at 4:28 PM, Greg wrote:
> 
> > Hi,
> > 
> > i must sort the documents by the version number ("\_version"- field).  
> > How can I do that?
> > 
> > Thanks.
> > 
> > Greg

---

<div class="post-metadata">

**Author:** ![kevins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevins/32/946_2.png) [@kevins](https://discuss.elastic.co/u/kevins)\
**Post date:** [November 13, 2013, 12:28am UTC](https://discuss.elastic.co/t/sort-by--version-field/8169/4 "2013-11-13T00:28:53Z")

</div>

I was looking for this same feature.

My use case is to return the documents that have been updated the most number of times.

It is used in a frequency algorithm that powers an autocomplete. (Yeah, another one of those).

When I index a document I will add certain words to the autocomplete type. If I can sort by \_version:desc I will get back the most frequent words by default.

e.g.

type "in" autocompletes with

indiana (\_version:4343)  
indy (\_version:1234)  
inside (\_version:432)  
etc.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 18, 2013, 11:56pm UTC](https://discuss.elastic.co/t/sort-by--version-field/8169/5 "2013-11-18T23:56:37Z")

</div>

The version field is not part of the document, but is stored in memory that  
is updated in parallel with updating the document in Lucene. Since the  
field is not part of the document, it is not indexed and thefore not  
queryable or sortable.

Cheers,

Ivan

On Tue, Nov 12, 2013 at 4:28 PM, kevins [kevinsteger@gmail.com](mailto:kevinsteger@gmail.com) wrote:

> I was looking for this same feature.
> 
> My use case is to return the documents that have been updated the most  
> number of times.
> 
> It is used in a frequency algorithm that powers an autocomplete. (Yeah,  
> another one of those).
> 
> When I index a document I will add certain words to the autocomplete type.  
> If I can sort by \_version:desc I will get back the most frequent words by  
> default.
> 
> e.g.
> 
> type "in" autocompletes with
> 
> indiana (\_version:4343)  
> indy (\_version:1234)  
> inside (\_version:432)  
> etc.
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Sort-by-version-field-tp4019525p4044170.html](http://elasticsearch-users.115913.n3.nabble.com/Sort-by-version-field-tp4019525p4044170.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [July 6, 2017, 2:06am UTC](https://discuss.elastic.co/t/sort-by--version-field/8169/6 "2017-07-06T02:06:22Z")

</div>


