Query for name and job title

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!

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'])

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