How to sort result set in order of matching words

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
}

{
"query": {
"bool": {
"must": [{
"wildcard": {
"name": "heinz*"
}
}, {
"wildcard": {
"name": "mayer*"
}
}, {
"span_near": {
"clauses": [{
"span_term": {
"name": {
"value": "heinz"
}
}
}, {
"span_term": {
"name": {
"value": "mayer"
}
}
}],
"slop": 4,
"in_order": true
}
}],
"must_not": ,
"should": [{
"span_first": {
"match": {
"span_term": {
"name": "heinz"
}
},
"end": 1
}
}, {
"span_first": {
"match": {
"span_term": {
"name": "mayer"
}
},
"end": 2
}
}],
"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
}