Elasticsearch-rails gem - completion helper

Hi I want to use completion helper using elasticsearch-rails gem.

I tried to follow the ruby ​​client documentation, but I don't have the same results when using the rails mail client and client.

Works with the 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 a 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 the term with completion, but still doesn't work:

Article.__elasticsearch__.client.suggest(:index => '', :body => {
        :suggestions => {
            :text => "s",
            :completion => {
                :field => 'suggest'
            }
        }
    })

      

+3


source to share


2 answers


I found my problem:



Article.__elasticsearch__.client.suggest(:index => Article.index_name, :body => {
        :suggestions => {
            :text => "s",
            :completion => {
                :field => 'suggest'
            }
        }
    })

      

0


source


Here's 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
                                               } 
                                          } 
                              }

      

+1


source







All Articles