# Sorting equal scores by field length?

**URL:** <https://discuss.elastic.co/t/sorting-equal-scores-by-field-length/20047>\
**Category:** Elasticsearch\
**Created:** [October 2, 2014, 11:33am UTC](https://discuss.elastic.co/t/sorting-equal-scores-by-field-length/20047 "2014-10-02T11:33:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee\_Gee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lee_gee/32/1217_2.png) [@Lee\_Gee](https://discuss.elastic.co/u/Lee_Gee)\
**Post date:** [October 2, 2014, 11:33am UTC](https://discuss.elastic.co/t/sorting-equal-scores-by-field-length/20047/1 "2014-10-02T11:33:01Z")

</div>

Is it possible to sort equally-scored results by the length of the field?

Or am I doing something else incorrectly?

With an edge\_ngram filter on a keyword field, with search term S, I see  
SUPER comes before S in my results.

As a last resort, I could add a field to reflect the length of the keyword  
field, or even turn on dynamic scripting, but I imagine i am missing  
something vital....

Thanks  
Lee

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/3de35adb-4573-4322-b2c0-c1e49320102d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3de35adb-4573-4322-b2c0-c1e49320102d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [October 2, 2014, 1:41pm UTC](https://discuss.elastic.co/t/sorting-equal-scores-by-field-length/20047/2 "2014-10-02T13:41:34Z")

</div>

Hello Lee ,

There is a workaround for that.  
You need to enabled word count and then use that in the script.

Word count -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Script in scoring -

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

HTH.

Thanks  
Vineeth

On Thu, Oct 2, 2014 at 4:33 AM, Lee Gee [leegee@gmail.com](mailto:leegee@gmail.com) wrote:

> Is it possible to sort equally-scored results by the length of the field?
> 
> Or am I doing something else incorrectly?
> 
> With an edge\_ngram filter on a keyword field, with search term S, I see  
> SUPER comes before S in my results.
> 
> As a last resort, I could add a field to reflect the length of the keyword  
> field, or even turn on dynamic scripting, but I imagine i am missing  
> something vital....
> 
> Thanks  
> Lee
> 
> --  
> 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/3de35adb-4573-4322-b2c0-c1e49320102d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3de35adb-4573-4322-b2c0-c1e49320102d%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/3de35adb-4573-4322-b2c0-c1e49320102d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3de35adb-4573-4322-b2c0-c1e49320102d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nRGQ%3D6BF5HTdnMQ3hM8K7D%2BE-6C0BNzEScm81w8-uTkw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5nRGQ%3D6BF5HTdnMQ3hM8K7D%2BE-6C0BNzEScm81w8-uTkw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Lee\_Gee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lee_gee/32/1217_2.png) [@Lee\_Gee](https://discuss.elastic.co/u/Lee_Gee)\
**Post date:** [October 7, 2014, 12:57pm UTC](https://discuss.elastic.co/t/sorting-equal-scores-by-field-length/20047/3 "2014-10-07T12:57:51Z")

</div>

Thank you, Vineeth!

On Thursday, October 2, 2014 2:41:42 PM UTC+1, vineeth mohan wrote:

> Hello Lee ,
> 
> There is a workaround for that.  
> You need to enabled word count and then use that in the script.
> 
> Word count -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html)  
> Script in scoring -  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-advanced-scripting.html#_term_statistics_2)
> 
> HTH.
> 
> Thanks  
> Vineeth
> 
> On Thu, Oct 2, 2014 at 4:33 AM, Lee Gee \<[lee...@gmail.com](mailto:lee...@gmail.com) \<javascript:\>\>  
> wrote:
> 
> > Is it possible to sort equally-scored results by the length of the field?
> > 
> > Or am I doing something else incorrectly?
> > 
> > With an edge\_ngram filter on a keyword field, with search term S, I see  
> > SUPER comes before S in my results.
> > 
> > As a last resort, I could add a field to reflect the length of the  
> > keyword field, or even turn on dynamic scripting, but I imagine i am  
> > missing something vital....
> > 
> > Thanks  
> > Lee
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/3de35adb-4573-4322-b2c0-c1e49320102d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3de35adb-4573-4322-b2c0-c1e49320102d%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/3de35adb-4573-4322-b2c0-c1e49320102d%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/3de35adb-4573-4322-b2c0-c1e49320102d%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/ff650736-935f-44dc-8a3b-7254cd1a5e4c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ff650736-935f-44dc-8a3b-7254cd1a5e4c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:57am UTC](https://discuss.elastic.co/t/sorting-equal-scores-by-field-length/20047/4 "2017-07-06T00:57:53Z")

</div>


