Hi I want to use the completion suggester using the elasticsearch-rails gem.
I tried to follow the ruby client documentation but I don't have the same results when using postman and the rails client.
Works with postman:
{
"suggestions" : {
"text" : "s",
"completion" : {
"field" : "suggest"
}
}
}
Results:
{
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"suggestions": [
{
"text": "s",
"offset": 0,
"length": 3,
"options": [
{
"text": "superman",
"score": 1,
"payload": {
"id": 922,
"tumb_img": "/user/avatar/20/thumb_img.jpg"
}
}
]
}
]
}
But not with the ruby client:
Article.__elasticsearch__.client.suggest(:index => '', :body => {
:suggestions => {
:text => "s",
:term => {
:field => 'suggest'
}
}
})
Results:
{
"_shards": {
"total": 11,
"successful": 11,
"failed": 0
},
"suggestions": [
{
"text": "s",
"offset": 0,
"length": 1,
"options": []
}
]
}
I also tried replacing term with completion but still doesn't work:
Article.__elasticsearch__.client.suggest(:index => '', :body => {
:suggestions => {
:text => "s",
:completion => {
:field => 'suggest'
}
}
})
Here what works for me.
Elasticsearch::Model.client.suggest index: 'articles',
body: {
suggestion: {
text: 's',
completion: {
field: 'suggest'
#suggest or any field that has mapping with type: 'completion', payloads: true
}
}
}
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