I'm trying to get suggestions from a multifield. I can't find examples like this, so maybe it's not the best idea, but I'm interested in your opinion.
mapping:
POST /authors { "mappings": { "author": { "properties": { "name": { "type": "multi_field", "fields": { "name": { "type": "string", "index": "analyzed" }, "ac": { "type": "completion", "index_analyzer": "simple", "search_analyzer": "simple", "payloads": true } } } } } } }
data:
POST /authors/author/1 { "name": "Fyodor Dostoevsky" }
query:
POST /authors/_suggest { "authorsAutocomplete": { "text": "fyodor", "completion": { "field": "name.ac" } } }
Requirements are:
any ideas how can I achieve these?
Firstly, the suggesters don't work well in multi-fields, so you could want to put it outside. Secondly, to make you query work with both the name and firstname, you have to choose the outputs/inputs in when indexing the data.
Example of working code for SENSE:
POST authors
PUT authors/_mapping/author
{
"properties" : {
"name" : { "type" : "string" },
"suggest" : { "type" : "completion"}
}
}
POST authors/author/1
{
"name": "Fyodor Dostoevsky",
"suggest": {
"input": ["Dostoevsky", "Fyodor"],
"output": "Fyodor Dostoevsky"
}
}
POST authors/_suggest
{
"authorsAutocomplete": {
"text": "d",
"completion": {
"field": "suggest"
}
}
}
DELETE authors
Result:
{
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"authorsAutocomplete": [
{
"text": "d",
"offset": 0,
"length": 1,
"options": [
{
"text": "Fyodor Dostoevsky",
"score": 1
}
]
}
]
}
Filters are not available for suggestions. To implement some kind of filtering, you can look at this blog post about the use of context in suggestions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With