# Displaying the value of the property that best matches a given search

**URL:** <https://discuss.elastic.co/t/displaying-the-value-of-the-property-that-best-matches-a-given-search/120555>\
**Category:** Elasticsearch\
**Created:** [February 20, 2018, 5:25am UTC](https://discuss.elastic.co/t/displaying-the-value-of-the-property-that-best-matches-a-given-search/120555 "2018-02-20T05:25:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![munduruca](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@munduruca](https://discuss.elastic.co/u/munduruca)\
**Post date:** [February 20, 2018, 5:25am UTC](https://discuss.elastic.co/t/displaying-the-value-of-the-property-that-best-matches-a-given-search/120555/1 "2018-02-20T05:25:22Z")

</div>

Hello!

I have a search box which I should use to search across multiple fields a given text. The problem is that I need to display the top ten values according to the property matching score.

My "restaurant\_crew" index, for instance, has the following properties:

"restaurant\_role"  
"dish"  
"name"  
"email"  
"phone"

Let's say that my user searched "ana":

(sudo elasticsearch query)  
query: “ana”  
match\_all:  
fields : ["restaurant\_role","dish","name","email","phone"]

I have two hits but I don’t need here to pass to my front end the documents. I would need to Identify which property has “the greatest matching value”.

[first document]  
{"restaurant\_role":"chef", "name":"ana gonzales", "email":"ana@food.com", "phone":7657653245}

In this case, it was “ana gonzales”. So I need to pass this value to my front end.

[second document]  
{"restaurant\_role":"food analyst", "name":"jane smith", "email":"jane@food.com", "phone":098098098}

For this document the “match” was related to the restaurant\_role value “food analyst”.  
Consequently, I need to pass “food analyst” to my front end.

In the end, my desired result for this query would be something that looks like that:  
{“hits”:  
{“hits”:{  
{"name":"ana gonzales"},  
{"restaurant\_role":"food analyst"}  
}  
}  
}

In SQL, I could use nested queries ( some crazy select from select from select union select) to work this out but I don’t really know how to do this using Elasticsearch.

Thanks in advance!

---

<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:** [March 20, 2018, 5:25am UTC](https://discuss.elastic.co/t/displaying-the-value-of-the-property-that-best-matches-a-given-search/120555/2 "2018-03-20T05:25:33Z")

</div>

Closed on March 20, 2018, 5:25am UTC

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