# Phrase Suggester with multiple Fields

**URL:** <https://discuss.elastic.co/t/phrase-suggester-with-multiple-fields/18223>\
**Category:** Elasticsearch\
**Created:** [June 20, 2014, 2:01am UTC](https://discuss.elastic.co/t/phrase-suggester-with-multiple-fields/18223 "2014-06-20T02:01:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brupm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brupm/32/746_2.png) [@brupm](https://discuss.elastic.co/u/brupm)\
**Post date:** [June 20, 2014, 2:01am UTC](https://discuss.elastic.co/t/phrase-suggester-with-multiple-fields/18223/1 "2014-06-20T02:01:21Z")

</div>

I am using the phrase suggester to implement did-you-mean functionality. My  
source field is named did\_you\_mean\_source which is a combination of first  
and last name with a space in the middle.

When I search for say "allex blak" I do get fairly descent suggestions,  
including the "alex black" I am hoping to get.

_The problem is I also get "alex [any other first and/or last name present  
in the index that has a subbestion for blak]". This suggestion doesn't  
match to any "results" (not suggestion result) but actual search result in  
my index._

So you search for first and last name which you happen to misspelled, but  
the suggestions propose another spelling which doesn't actually return any  
index search results. In other words, I need to somehow preserve the  
identity that one is a first name and the other is a last name.

What I am trying to achieve is a did-you-mean functionality where I can  
type a first and last name, and get suggestions based of of the  
did\_you\_mean\_source but only where both typed words match a document.

Here's my analyzer:  
did\_you\_mean:  
type: custom  
tokenizer: standard  
filter: ["lowercase", "trim",]

Here's the suggest part of my query:

"suggest": {  
"text": "allex blak",  
"did\_you\_mean" : {  
"phrase" : {  
"field": "did\_you\_mean\_source",  
"real\_word\_error\_likelihood": 0.90,  
"max\_errors": 1,  
"direct\_generator" : [{  
"field" : "did\_you\_mean\_source",  
"suggest\_mode" : "always",  
"min\_word\_length" : 3,  
"size": 5,  
"prefix\_length": 2,  
"min\_doc\_freq": 1  
}]  
}  
}  
}

Here's what my mappings look like:

{  
"development\_search\_suggestions": {  
"mappings": {  
"search\_suggestion": {  
"\_all": {  
"enabled": false  
},  
"properties": {  
"did\_you\_mean\_source": {  
"type": "string",  
"analyzer": "did\_you\_mean"  
},  
"keywords": {  
"type": "string",  
"index\_options": "offsets",  
"analyzer": "full",  
"fields": {  
"partial": {  
"type": "string",  
"index\_options": "offsets",  
"index\_analyzer": "partial\_auto\_suggest",  
"search\_analyzer": "full\_with\_auto\_suggest\_synonyms"  
},  
"synonymic": {  
"type": "string",  
"index\_analyzer": "full\_with\_auto\_suggest\_synonyms",  
"search\_analyzer": "full"  
}  
}  
},  
"keywords\_auxiliary": {  
"type": "string",  
"index\_options": "offsets",  
"analyzer": "full",  
"fields": {  
"partial": {  
"type": "string",  
"index\_options": "offsets",  
"index\_analyzer": "partial\_auto\_suggest",  
"search\_analyzer": "full\_with\_auto\_suggest\_synonyms"  
},  
"synonymic": {  
"type": "string",  
"index\_analyzer": "full\_with\_auto\_suggest\_synonyms",  
"search\_analyzer": "full"  
}  
}  
}  
}  
}  
}  
}  
}

_A few examples:_

Say my index contains the following documents with first and last name in  
respective orders:  
bruno miranda  
miranda bella  
bran scott

If I search for: "brno miranda" I should get a suggestion for "bruno  
miranda" but I should not have suggestions for "bran miranda" because that  
document doesn't exist in the db. It's simply a mismatch of a first name +  
a different document's last name.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e4f16d17-a0fd-4a4f-88fd-bbeaf7238353%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e4f16d17-a0fd-4a4f-88fd-bbeaf7238353%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:21am UTC](https://discuss.elastic.co/t/phrase-suggester-with-multiple-fields/18223/2 "2017-07-06T01:21:03Z")

</div>


