# Query for the name search

**URL:** <https://discuss.elastic.co/t/query-for-the-name-search/5193>\
**Category:** Elasticsearch\
**Created:** [August 18, 2011, 4:40pm UTC](https://discuss.elastic.co/t/query-for-the-name-search/5193 "2011-08-18T16:40:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mfeingold](https://avatars.discourse-cdn.com/v4/letter/m/ecb155/32.png) [@mfeingold](https://discuss.elastic.co/u/mfeingold)\
**Post date:** [August 18, 2011, 4:40pm UTC](https://discuss.elastic.co/t/query-for-the-name-search/5193/1 "2011-08-18T16:40:46Z")

</div>

I have a document with 2 fields - first name and last name.

For the last name I would like to use exact match, phonetic match and  
(may be) wild card - specifically \* in the end. I would also like to  
do fuzzy search with edit distance no more than 2 char.

For the first name I want the same plus name synonyms (Beth vs Lisa).

Here is my settings file I used for indexing the data [https://gist.github.com/1154453](https://gist.github.com/1154453)

What I am struggling with now is how to build a query out of the  
string with the first name and the last name. I can (I think) build  
reasonable query I can use to run the name string separately against  
first name or last name. How should I combine them so that record John  
John does not jump in front of John Smith when I run the query string  
"John Smith"?

In other words when the document matches both fields how can I  
differentiate between 2 different terms from the query string matching  
each field vs the same term matching both fields.

Also how can I account for the order in which they match - if the  
terms in the query string are in the order of first name than last  
name - I would like to give it a bigger rank than if the order is  
reversed.

Can it be done?

---

<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, 3:56am UTC](https://discuss.elastic.co/t/query-for-the-name-search/5193/2 "2017-07-06T03:56:40Z")

</div>


