# Sorting autocomplete results by numeric property

**URL:** <https://discuss.elastic.co/t/sorting-autocomplete-results-by-numeric-property/15329>\
**Category:** Elasticsearch\
**Created:** [January 20, 2014, 9:05pm UTC](https://discuss.elastic.co/t/sorting-autocomplete-results-by-numeric-property/15329 "2014-01-20T21:05:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![redrubia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redrubia/32/1554_2.png) [@redrubia](https://discuss.elastic.co/u/redrubia)\
**Post date:** [January 20, 2014, 9:05pm UTC](https://discuss.elastic.co/t/sorting-autocomplete-results-by-numeric-property/15329/1 "2014-01-20T21:05:46Z")

</div>

Seems, I have an issue with sorting the results. Below is my config:

```
curl -X PUT localhost:9200/companies -d '

```

{  
"settings" : {  
"analysis" : {  
"char\_filter": {  
"punctuation\_removal": {  
"type": "pattern\_replace",  
"pattern": "[\.,/]",  
"replacement": " "  
}  
},  
"analyzer" : {  
"my\_edge\_ngram\_analyzer" : {  
"char\_filter" :["punctuation\_removal"],  
"tokenizer" : "my\_edge\_ngram\_tokenizer",  
"filter" : ["standard", "lowercase"]  
}  
},  
"tokenizer" : {  
"my\_edge\_ngram\_tokenizer" : {  
"type" : "edgeNGram",  
"min\_gram" : "1",  
"max\_gram" : "5",  
"token\_chars": ["letter", "digit"]  
}  
}  
}  
},  
"mappings": {  
"company" : {  
"properties" : {  
"name" : { "type" : "string" },  
"count" : {"type": "long" },  
"name\_suggest" : {  
"type" : "completion",  
"index\_analyzer": "my\_edge\_ngram\_analyzer",  
"search\_analyzer": "my\_edge\_ngram\_analyzer"  
}  
}  
}  
}  
}'

Here are examples to put into ES:

```
curl -X PUT localhost:9200/companies/company/1 -d '
{
  "name" : "1800flowers",
  "count": 1000,
  "name_suggest" : {
    "input" : [
      "1800 flowers.Com, Inc",
      "1800 Flowers","1800-Flowers.com",
      "1 800 Flowers",
      "www.1800flowers.com",
      "1800Flowers.com", 
      "Inc,1-800-FLOWERS.COM",
      "1-800-FLOWERS.COM, INC",
      "1800Flowers",
      "1800Flowers Inc",
      "1800Flowers.com (Consultant)",
      "1-800-FLOWERS","1800Flowers.com",
      "1800FLOWERS INTERNATIONAL",
      "1-800 Flowers",
      "1-800 FLOWERS.COM, INC",
      "1-800-FLOWERS, Inc",
      "1800 flowers.com",
      "1-800Flowers.com",
      "1-800 flowers.com",
      "1800 Flowers Inc"
    ],
    "output" : "1800 Flowers"
  }
}'

curl -X PUT localhost:9200/companies/company/2 -d '
{
  "name" : "1800 Ruby",
  "count": 10000,
  "name_suggest" : {
    "input" : [
     "1800"
    ],
    "output" : "1800 Ruby"
  }
}'

```

Now clearly if I do a text search on 1800, I should get both of these objects back, giving output "1800 Flowers", "1800 Ruby".

Now really, I would like these results to be sorted by count, descending, so that I should have: "1800 Ruby", "1800 Flowers" but this isn't working!

```
curl -X POST localhost:9200/companies/_suggest -d '
{
  "query":{
  "companies" : {
    "text" : "18",
    "completion" : {
      "field" : "name_suggest"
    }
  }
  },
  "sort": [{"count": {"order": "desc"} }]
}'

```

So in summary I would firstly like the output to be given, then secondly to list in sorted order by the property count.

Thanks

---

<div class="post-metadata">

**Author:** ![redrubia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/redrubia/32/1554_2.png) [@redrubia](https://discuss.elastic.co/u/redrubia)\
**Post date:** [January 20, 2014, 10:45pm UTC](https://discuss.elastic.co/t/sorting-autocomplete-results-by-numeric-property/15329/2 "2014-01-20T22:45:07Z")

</div>

I've now figured, one way of doing this is to add a "weight" element in name suggest and hence the largest will be returned. However am I right that there is no way to automatically refer to 'count' which is a property of company.

---

<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:55am UTC](https://discuss.elastic.co/t/sorting-autocomplete-results-by-numeric-property/15329/3 "2017-07-06T01:55:45Z")

</div>


