Hi there, im trying to get a phrase suggester to work - So far, im not very successfull!
I basically followed the guide in the docs - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html
with a few differences:
title.trigram = title.suggest
Heres are some documents to show you some structure \ expected results:
{
"_index": "myIndex",
"_type": "article",
"_id": "b5893c47-7bbc-4eb1-b96e-3d621639d591",
"_score": 0.71896636,
"_source": {
"title": "Alloy Meet"
}
},
{
"_index": "myIndex",
"_type": "article",
"_id": "8b2eafb2-c8d5-41d0-a561-a525d42a38b2",
"_score": 0.6925415,
"_source": {
"title": "Enhances Risk Management"
}
},
{
"_index": "myIndex",
"_type": "article",
"_id": "673903fe-8562-4c46-9cca-b90dd6ed41e2",
"_score": 0.6597031,
"_source": {
"title": "Alloy Saves Bears"
}
},
{
"_index": "myIndex",
"_type": "article",
"_id": "30f44007-6cea-4d4d-b730-07f006f5dcdf",
"_score": 0.61461323,
"_source": {
"title": "Download Alloy Track"
}
},
{
"_index": "myIndex",
"_type": "article",
"_id": "1c4af28b-fb26-42e5-8d8e-cc3dbe72d2f6",
"_score": 0.61090285,
"_source": {
"title": "Alloy Track"
}
},
Backend code
-
Settings up the index template - This seems to work properly when inspecting the mapping:
var result = _client.PutIndexTemplate("myindextemplate", it => it .Template("myindex_*") .Settings(settings => settings // Analyzers .Analysis(ana => ana .Analyzers(a => a .Custom("trigram", tri => tri .Filters("standard", "shingle") .Tokenizer("standard") ) .Custom("reverse", tri => tri .Filters("standard", "reverse") .Tokenizer("standard") ) ) .TokenFilters(tf => tf .Shingle("shingle", shi => shi .MinShingleSize(2) .MaxShingleSize(3) ) ) ) ) //Mappings .Mappings(m => m .Map < art > (map => map .AutoMap(0) .Properties(prop => prop .Text(p => p .Name(o => o.Language) ) .Text(p => p .Name(o => o.ContentLink) ) .Text(p => p .Name(o => o.Title) .Fields(o => o .Text(oo => oo .Name("suggest") .Analyzer("trigram") ) .Text(oo => oo .Name("reverse") .Analyzer("reverse") ) ) ) ) ) ));
The search, done in Kibana:
POST /myIndex/_search
{
"suggest": {
"text" : "all meet",
"simple_phrase" : {
"phrase" : {
"field" : "title.suggest",
"real_word_error_likelihood": 0.10,
"size" : 5,
"direct_generator" : [ {
"field" : "title.suggest",
"suggest_mode" : "always",
"min_word_length" : 1
} ],
"collate": {
"query": {
"inline" : {
"match": {
"{{field_name}}" : "{{suggestion}}"
}
}
},
"params": {"field_name" : "title"},
"prune": true
}
}
}
}
}
Search Response
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 15,
"successful": 15,
"failed": 0
},
"hits": {
"total": 0,
"max_score": 0,
"hits": []
},
"suggest": {
"simple_phrase": [
{
"text": "all meet",
"offset": 0,
"length": 8,
"options": []
}
]
}
}
Expected result:
I would expect "all" to be corrected to "alloy"
Appreciate any help!