# I am trying to search by name

**URL:** <https://discuss.elastic.co/t/i-am-trying-to-search-by-name/151889>\
**Category:** Elasticsearch\
**Created:** [October 10, 2018, 4:03pm UTC](https://discuss.elastic.co/t/i-am-trying-to-search-by-name/151889 "2018-10-10T16:03:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archana1](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@archana1](https://discuss.elastic.co/u/archana1)\
**Post date:** [October 10, 2018, 4:03pm UTC](https://discuss.elastic.co/t/i-am-trying-to-search-by-name/151889/1 "2018-10-10T16:03:47Z")

</div>

HI  
I am very new to elasticsearch. I am trying to search by name(User can enter firstname or lastname). For example if they give 'John' i should get john and also 'Jhonson'. But my current query is giving only john.  
Can anyone help me with this.

below is my current query:  
{  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"name": {  
"query": "lee"  
}  
}  
},  
{  
"match\_phrase": {  
"isValid": true  
}  
}  
],  
"filter": {  
"bool": {  
"must": [  
{  
"nested": {  
"path": "practices",  
"inner\_hits": {  
"size": 10000,  
"\_source": {  
"includes": "practices.id"  
}  
},  
"query": {  
"bool": {  
"must": {  
"match\_all": {}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"match\_phrase": {  
"practices.practiceType": "pcp"  
}  
},  
{  
"range": {  
"practices.effectiveDate": {  
"lte": "2018-09-10"  
}  
}  
},  
{  
"range": {  
"practices.terminationDate": {  
"gte": "2018-09-10"  
}  
}  
},  
{  
"match\_phrase": {  
"practices.isDirectoryIndicator": true  
}  
},  
{  
"match\_phrase": {  
"practices.prefix": "COMM"  
}  
},  
{  
"match\_phrase": {  
"practices.isValid": true  
}  
},  
{  
"nested": {  
"path": "practices.addresses",  
"inner\_hits": {  
"size": 10000,  
"\_source": {  
"includes": "practices.addresses.id"  
}  
},  
"query": {  
"bool": {  
"must": {  
"match\_all": {}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"match\_phrase": {  
"practices.addresses.state": "CA"  
}  
},  
{  
"match\_phrase": {  
"practices.addresses.directoryIndicator": "I"  
}  
},  
{  
"range": {  
"practices.addresses.effectiveDate": {  
"lte": "2018-09-10"  
}  
}  
},  
{  
"range": {  
"practices.addresses.terminationDate": {  
"gte": "2018-09-10"  
}  
}  
}  
],  
"must\_not": [  
{  
"match\_phrase": {  
"practices.addresses.type": "REM"  
}  
}  
]  
}  
}  
}  
}  
}  
}  
],  
"must\_not": []  
}  
}  
}  
}  
}  
}  
],  
"must\_not": []  
}  
}  
}  
},  
"size": 10000,  
"from": 0  
}

---

<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:** [November 7, 2018, 4:16pm UTC](https://discuss.elastic.co/t/i-am-trying-to-search-by-name/151889/2 "2018-11-07T16:16:13Z")

</div>

Closed on November 7, 2018, 4:16pm UTC

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