# Partial matching and exact matching in one query

**URL:** <https://discuss.elastic.co/t/partial-matching-and-exact-matching-in-one-query/89529>\
**Category:** Elasticsearch\
**Created:** [June 15, 2017, 8:38am UTC](https://discuss.elastic.co/t/partial-matching-and-exact-matching-in-one-query/89529 "2017-06-15T08:38:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ChelseaCao](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@ChelseaCao](https://discuss.elastic.co/u/ChelseaCao)\
**Post date:** [June 15, 2017, 8:38am UTC](https://discuss.elastic.co/t/partial-matching-and-exact-matching-in-one-query/89529/1 "2017-06-15T08:38:37Z")

</div>

Hi there,

I am writing a query for searching a name.  
requirements (I have name,first\_name, last\_name fields that can be searched in type Contact):

1. first return match\_phrase result if possible
2. then return partial matching result whose prefix for each word.
3. then return any result that contain the string  
e.g. search for "He Mi "  
I need a query that will return "He Mi " exact match first if exists.  
then return prefix matching for each word like "Helen Mi" "Henry Mike" "Mitchell Henry" etc...  
last return single partial word matching result : "He Berry" "Mike C" etc.  
my query like below:  
GET /crm/Contact/\_search  
{  
"query": {  
"wildcard" : { "Name" : "he\*mi" }  
}  
}  
but there is no return. However, I should have had result as shown above. How can I deal with it?

---

<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 13, 2017, 8:38am UTC](https://discuss.elastic.co/t/partial-matching-and-exact-matching-in-one-query/89529/2 "2017-07-13T08:38:54Z")

</div>

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