# Looking for ideas how to sort by a field that looks like 400234.12.4

**URL:** <https://discuss.elastic.co/t/looking-for-ideas-how-to-sort-by-a-field-that-looks-like-400234-12-4/17361>\
**Category:** Elasticsearch\
**Created:** [May 6, 2014, 9:46am UTC](https://discuss.elastic.co/t/looking-for-ideas-how-to-sort-by-a-field-that-looks-like-400234-12-4/17361 "2014-05-06T09:46:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mooky](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@mooky](https://discuss.elastic.co/u/mooky)\
**Post date:** [May 6, 2014, 9:46am UTC](https://discuss.elastic.co/t/looking-for-ideas-how-to-sort-by-a-field-that-looks-like-400234-12-4/17361/1 "2014-05-06T09:46:45Z")

</div>

I have a reference field that is pseudo numeric. Sorting alphabetically  
produces the wrong results.

e.g. the following values should be sorted like this:  
3045.5.2  
3045.5.12  
3045.15.2

I can't change the reference format - to pad it with zeros.  
But I did think I could create a field that was padded with zeros - and  
sort using that.  
I was hoping I could keep it out of the source document - but I haven't  
figured out how I can do some scripted formatting yet - using perhaps a  
multi-field.

I would greatly appreciate any cunning tricks that could be used to get  
this done.

--  
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/34123a15-e8d3-4191-b866-671064420f44%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/34123a15-e8d3-4191-b866-671064420f44%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [May 6, 2014, 11:08am UTC](https://discuss.elastic.co/t/looking-for-ideas-how-to-sort-by-a-field-that-looks-like-400234-12-4/17361/2 "2014-05-06T11:08:01Z")

</div>

may be using a script score function? [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#\_script\_score](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_script_score)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 6 mai 2014 à 11:46:51, mooky ([nick.minutello@gmail.com](mailto:nick.minutello@gmail.com)) a écrit:

I have a reference field that is pseudo numeric. Sorting alphabetically produces the wrong results.

e.g. the following values should be sorted like this:  
3045.5.2  
3045.5.12  
3045.15.2

I can't change the reference format - to pad it with zeros.  
But I did think I could create a field that was padded with zeros - and sort using that.  
I was hoping I could keep it out of the source document - but I haven't figured out how I can do some scripted formatting yet - using perhaps a multi-field.

I would greatly appreciate any cunning tricks that could be used to get this done.

--  
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/34123a15-e8d3-4191-b866-671064420f44%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/34123a15-e8d3-4191-b866-671064420f44%40googlegroups.com).  
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/etPan.5368c292.431bd7b7.5c36%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5368c292.431bd7b7.5c36%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [May 6, 2014, 11:09am UTC](https://discuss.elastic.co/t/looking-for-ideas-how-to-sort-by-a-field-that-looks-like-400234-12-4/17361/3 "2014-05-06T11:09:10Z")

</div>

I meant sort script: [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#\_script\_based\_sorting](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_script_based_sorting)

although score script should help as well.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 6 mai 2014 à 13:08:05, David Pilato (david@pilato.fr) a écrit:

may be using a script score function? [http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#\_script\_score](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_script_score)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 6 mai 2014 à 11:46:51, mooky ([nick.minutello@gmail.com](mailto:nick.minutello@gmail.com)) a écrit:

I have a reference field that is pseudo numeric. Sorting alphabetically produces the wrong results.

e.g. the following values should be sorted like this:  
3045.5.2  
3045.5.12  
3045.15.2

I can't change the reference format - to pad it with zeros.  
But I did think I could create a field that was padded with zeros - and sort using that.  
I was hoping I could keep it out of the source document - but I haven't figured out how I can do some scripted formatting yet - using perhaps a multi-field.

I would greatly appreciate any cunning tricks that could be used to get this done.

--  
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/34123a15-e8d3-4191-b866-671064420f44%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/34123a15-e8d3-4191-b866-671064420f44%40googlegroups.com).  
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/etPan.5368c2d6.62bbd95a.5c36%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.5368c2d6.62bbd95a.5c36%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![mooky](https://avatars.discourse-cdn.com/v4/letter/m/43a26b/32.png) [@mooky](https://discuss.elastic.co/u/mooky)\
**Post date:** [May 7, 2014, 2:04pm UTC](https://discuss.elastic.co/t/looking-for-ideas-how-to-sort-by-a-field-that-looks-like-400234-12-4/17361/4 "2014-05-07T14:04:55Z")

</div>

Thanks.

On Tuesday, 6 May 2014 12:09:10 UTC+1, David Pilato wrote:

> I meant sort script:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_script_based_sorting)
> 
> although score script should help as well.
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 6 mai 2014 à 13:08:05, David Pilato ([da...@pilato.fr](mailto:da...@pilato.fr) \<javascript:\>) a  
> écrit:
> 
> may be using a script score function?  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html#_script_score)
> 
> ```
> -- 
> 
> ```
> 
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 6 mai 2014 à 11:46:51, mooky ([nick.mi...@gmail.com](mailto:nick.mi...@gmail.com) \<javascript:\>) a  
> écrit:
> 
> I have a reference field that is pseudo numeric. Sorting alphabetically  
> produces the wrong results.
> 
> e.g. the following values should be sorted like this:  
> 3045.5.2  
> 3045.5.12  
> 3045.15.2
> 
> I can't change the reference format - to pad it with zeros.  
> But I did think I could create a field that was padded with zeros - and  
> sort using that.  
> I was hoping I could keep it out of the source document - but I haven't  
> figured out how I can do some scripted formatting yet - using perhaps a  
> multi-field.
> 
> I would greatly appreciate any cunning tricks that could be used to get  
> this done.
> 
> --  
> 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/34123a15-e8d3-4191-b866-671064420f44%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/34123a15-e8d3-4191-b866-671064420f44%40googlegroups.com)[https://groups.google.com/d/msgid/elasticsearch/34123a15-e8d3-4191-b866-671064420f44%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/34123a15-e8d3-4191-b866-671064420f44%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/ec333800-e092-4e8a-b9d1-5ea3492f4459%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ec333800-e092-4e8a-b9d1-5ea3492f4459%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, 1:31am UTC](https://discuss.elastic.co/t/looking-for-ideas-how-to-sort-by-a-field-that-looks-like-400234-12-4/17361/5 "2017-07-06T01:31:04Z")

</div>


