# How to sort result set in order of matching words

**URL:** <https://discuss.elastic.co/t/how-to-sort-result-set-in-order-of-matching-words/199095>\
**Category:** Elasticsearch\
**Created:** [September 11, 2019, 2:44pm UTC](https://discuss.elastic.co/t/how-to-sort-result-set-in-order-of-matching-words/199095 "2019-09-11T14:44:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yeldar\_Kossynbay](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yeldar_kossynbay/32/53999_2.png) [@Yeldar\_Kossynbay](https://discuss.elastic.co/u/Yeldar_Kossynbay)\
**Post date:** [September 11, 2019, 2:44pm UTC](https://discuss.elastic.co/t/how-to-sort-result-set-in-order-of-matching-words/199095/1 "2019-09-11T14:44:14Z")

</div>

Hi guys,

I have a couple words "heinz meyer"

my query returns:

- Heinz A. Meyer
- Heinz Meyer GmbH Heizung-Sanitär
- Heinz Meyer
- Karl-Heinz Meyer GmbH

but i need, order by positions matching like next :

- Heinz Meyer
- Heinz Meyer GmbH Heizung-Sanitär
- Heinz A. Meyer
- Karl-Heinz Meyer GmbH

my query is:

> ```
> {
> "query": {
> "bool": {
> "must": [{
> "wildcard": {
> "name": "heinz*"
> }
> }, {
> "wildcard": {
> "name": "meyer*"
> }
> }],
> "must_not": [],
> "should": [],
> "filter": {
> "bool": {
> "must": [{
> "range": {
> "latestRevenueStatistics.revenue": {
> "gte": "0",
> "lte": "40000000"
> }
> }
> }, {
> "range": {
> "latestRevenueStatistics.number_of_employees": {
> "gte": "0",
> "lte": "300"
> }
> }
> }, {
> "term": {
> "addresses.postal_code_length": 5
> }
> }]
> }
> }
> }
> },
> "from": 0,
> "size": 10
> }
> 
> ```

---

<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:** [October 9, 2019, 7:18pm UTC](https://discuss.elastic.co/t/how-to-sort-result-set-in-order-of-matching-words/199095/3 "2019-10-09T19:18:51Z")

</div>

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