2014-12-21 136 views
3

您好我想使用elasticsearch-rails gem的completion suggesterelasticsearch-rails寶石 - 完成建議

我試圖按照紅寶石客戶端documentation,但使用郵遞員和rails客戶端時,我沒有相同的結果。

作品與郵差:

{ 
    "suggestions" : { 
     "text" : "s", 
     "completion" : { 
      "field" : "suggest" 
     } 
    } 
} 

結果:

{ 
    "_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" 
        } 
       } 
      ] 
     } 
    ] 
} 

但不可用紅寶石客戶端:

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

結果:

{ 
    "_shards": { 
     "total": 11, 
     "successful": 11, 
     "failed": 0 
    }, 
    "suggestions": [ 
     { 
      "text": "s", 
      "offset": 0, 
      "length": 1, 
      "options": [] 
     } 
    ] 
} 

我也試圖與竣工替代詞,但仍然不能正常工作:

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

回答

0

,我發現我的問題:

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

這裏是我的作品。

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 
               } 
              } 
           }