Autosuggest more then one word?


(roger-2) #1

Hi elasticsearchers

I'm trying to find a way to implement an auto suggest/complete search.

As far as I can see there is no way to search for more then one word
in an auto suggest string e.g. "Steve Boston" using nGram and
phrase_prefix.

Our elasticsearch.json looks like:

"index": {
"analysis" : {
"default": "textAnalyzer",
"analyzer": {
"nGramAnalyzer" : {
"type": "custom",
"tokenizer": "standard",
"filter" : ["standard", "lowercase", "nGramFilter"]
}
},
"filter" : {
"nGramFilter" : {
"type" : "nGram",
"min_gram" : 2,
"max_gram" : 25
}
}
}
}

Our index mapping looks like:

"userName": {
"type": "string",
"index": "analyzed",
"index_analyzer": "nGramAnalyzer",
"search_analyzer": "default",
"include_in_all": false,
"null_value": "na",
"boost": 2.0

}

And the indexed userName value is:
"Steve Miller, Boston"

The following query will work as excepted.

Split the query string "Steve Boston" or "Steve Bost" into a
bool:must:text query using phrase_prefix for each word from
the search string:

{
"query": {
"bool": {
"must": [
{
"text": {
"userName": {
"analyzer": "default",
"type": "phrase_prefix",
"query": "Steve"
}
}
},
{
"text": {
"userName": {
"analyzer": "default",
"type": "phrase_prefix",
"query": "Boston"
}
}
}
]
}
}
}

Is this the recommended concept for query more then one word?
Or is there a better/faster concept?

Regards
Roger Ineichen


END OF MESSAGE


(system) #2