MMa*_*gun 1 ruby-on-rails elasticsearch searchkick
当使用searchkick执行搜索时,我得到所有字段的结果。我想将响应限制为仅输出某些字段,例如title
。
# movie.rb
class Movie < ApplicationRecord
searchkick autocomplete: ['title']
end
# search_controller.rb
def autocomplete
render json: Movie.search(params[:query], autocomplete: true, limit: 10, fields: [:title])
end
Run Code Online (Sandbox Code Playgroud)
我的回应还是
[{"id":1,"title":"Megamind","director":"Tom McGrath","genre":"Animation | Action | Comedy","description":"The supervillain Megamind finally defeats his nemesis, the superhero Metro Man. But without a hero, he loses all purpose and must find new meaning to his life.","length":95,"year":2010,"imdb_id":"tt1001526","imdb_rating":"7.3","created_at":"2016-04-16T19:50:24.893Z","updated_at":"2016-04-16T19:50:24.893Z"}]
Run Code Online (Sandbox Code Playgroud)
我正试图只拿回标题。通过阅读不同的问题,我认为这应该与fields
我的搜索有关,但这不会改变响应。我也尝试使用_source
-attribute,但没有运气。
归档时间: |
|
查看次数: |
652 次 |
最近记录: |