# Query for name and job title

**URL:** <https://discuss.elastic.co/t/query-for-name-and-job-title/116339>\
**Category:** Elasticsearch\
**Created:** [January 20, 2018, 1:56pm UTC](https://discuss.elastic.co/t/query-for-name-and-job-title/116339 "2018-01-20T13:56:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![caseydm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caseydm/32/26771_2.png) [@caseydm](https://discuss.elastic.co/u/caseydm)\
**Post date:** [January 20, 2018, 1:56pm UTC](https://discuss.elastic.co/t/query-for-name-and-job-title/116339/1 "2018-01-20T13:56:38Z")

</div>

Hi all. I'm fairly new to Elasticsearch and am having trouble with a query that searches names and job title. I am using elasticsearch DSL and my query currently looks like this:

s = s.query("multi\_match", query=query, type='phrase', fields=['name', 'title'])

When searching for job titles the query works perfectly. But searching for names is too restrictive. For instance, searching the name 'John Good' will not return the record 'John B Good'. I think the problem is I am using a phrase query for both. I read some advice to remove the phrase query and let it default to best\_fields, which I tried. But the results are very loose, returning 'executive officer' as a top hit when querying 'police officer' even though there are many police officer records. The name query works and will return 'John B Good' when searching ' John Good', however, it also returns many variations of names with either John or Good in them, which I want to limit.

Please let me know if you have any suggestions on how to resolve this so I can leave the job title query the way it is, but improve the name portion so it returns better results!

---

<div class="post-metadata">

**Author:** ![caseydm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/caseydm/32/26771_2.png) [@caseydm](https://discuss.elastic.co/u/caseydm)\
**Post date:** [January 20, 2018, 7:17pm UTC](https://discuss.elastic.co/t/query-for-name-and-job-title/116339/2 "2018-01-20T19:17:27Z")

</div>

All you can disregard this. I fixed the problem by adding phrase\_slop=1. So the new query works well like this:

s = s.query("multi\_match", query=query, type='phrase', phrase\_slop=1, fields=['name', 'title'])

---

<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:** [February 17, 2018, 7:17pm UTC](https://discuss.elastic.co/t/query-for-name-and-job-title/116339/3 "2018-02-17T19:17:51Z")

</div>

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