# Prefix Query for People's names/Lookup

**URL:** https://discuss.elastic.co/t/prefix-query-for-peoples-names-lookup/59586
**Category:** Elasticsearch
**Created:** [September 1, 2016, 5:40pm UTC](https://discuss.elastic.co/t/prefix-query-for-peoples-names-lookup/59586 "2016-09-01T17:40:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![simi](https://avatars.discourse-cdn.com/v4/letter/s/cab0a1/32.png) [@simi](https://discuss.elastic.co/u/simi)
#### Post date: [September 1, 2016, 5:40pm UTC](https://discuss.elastic.co/t/prefix-query-for-peoples-names-lookup/59586/1 "2016-09-01T17:40:02Z")

</div>

Hello all,

First off, I need to say that I'm VERY new to both ElasticSearch and Lucene in general - so I apologize if this is a basic question. I'm struggling with a search question that is going against people's names (proper nouns). This is sort of like an autocomplete for people. Here's the basic requirement:

A user types in some characters, and if the terms (either first name **or** last name) starts with that query, return it (sorted, but that's not an issue). This includes multiple spaces in the query. So for example:

if a user types in "ch" - they will get the following in return:

Chris Jones  
Lisa Christenson  
Charlie Wells

....so far so good. If the user types in "ch j" or "j ch" then results would be:

Chris Jones

...again, no problem. I'm currently using a Prefix query on each one of the entries ("ch" and "j") and with a Boolean query (must for both inputted tokens). But here's where I'm starting to get lost. I'd like this functionality to work with dashed and apostrophes (or without them). For example:

Jason Von-Hanson  
Miles O'Brien

If a user types in "ob" OR "o'b" I'd like the return response to include:

Miles O'Brien

Is there any method via filters or such that could help me in this? I have this "largely" working. I have a field called "name" that contains the full name of the user. This is the Field I'm searching against. The only way to do this that I can think of is a bit kludgy. And that would be to modify the name field to include all versions such as:

"name" : "miles o'brien obrien"  
"name" : "jason von-hanson hanson"

Any thoughts or suggestions? Any help for a newbie would be most appreciated!

Cheers!

Simi

---

<div class="post-metadata">

### Author: ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)
#### Post date: [September 1, 2016, 7:29pm UTC](https://discuss.elastic.co/t/prefix-query-for-peoples-names-lookup/59586/2 "2016-09-01T19:29:45Z")

</div>

I'd play around with using a filter to remove the `'` and `-` entirely. Also have a look at the [completion](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html) suggester or using [edge ngram](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenfilter.html)s to avoid the need for usually slow prefix query. The completion suggester is going to be faster but uses heap memory to do its job. The edge ngrams are less fast and more complicated to set up but won't use heap memory.

---

<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 5, 2017, 10:23pm UTC](https://discuss.elastic.co/t/prefix-query-for-peoples-names-lookup/59586/3 "2017-07-05T22:23:07Z")

</div>


