# How to suggest by name sort by count field

**URL:** <https://discuss.elastic.co/t/how-to-suggest-by-name-sort-by-count-field/166079>\
**Category:** Elasticsearch\
**Created:** [January 29, 2019, 3:56am UTC](https://discuss.elastic.co/t/how-to-suggest-by-name-sort-by-count-field/166079 "2019-01-29T03:56:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elliotcrn](https://avatars.discourse-cdn.com/v4/letter/e/3d9bf3/32.png) [@elliotcrn](https://discuss.elastic.co/u/elliotcrn)\
**Post date:** [January 29, 2019, 3:56am UTC](https://discuss.elastic.co/t/how-to-suggest-by-name-sort-by-count-field/166079/1 "2019-01-29T03:56:01Z")

</div>

I'm using elasticsearch completion suggester to search and suggest keywords while user typing. It works fine but I also want to sort the results by count field.  
As I know I can't pass a field as the weight parameter. So how can I search by text field and sort by long field with elasticsearch just like in Instagram?

I also want to show only top 5 suggestion but size parameter also doesn't work

Mapping:

```auto
{
	"mappings":
	{
	 "doc": 
	 {
		"properties":
			{
				"keyword_name":{ "type" : "completion" },
				"keyword_user_count":{ "type" : "long" }
			} 
	 }			
	}
}

```

I've tried this but Sort doesn't change the result.

```auto
    "sort" : [
        { "keyword_user_count" : {"order" : "asc"}}
 
    ],
    "suggest": {
        "keyword-suggest" : {
            "prefix" : "key", 
            "completion" : { 
                "field" : "keyword_name" 
            }
        }
    }
     
}
```

---

<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:** [February 26, 2019, 3:56am UTC](https://discuss.elastic.co/t/how-to-suggest-by-name-sort-by-count-field/166079/2 "2019-02-26T03:56:06Z")

</div>

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