Search code examples
ruby-on-railselasticsearchsearchkick

Searchkick only return certain values, not all


When using searchkick to perform a search I get all fields as a result. I would like to limit the response to only output certain fields like 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

My response is still

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

I am trying to only get the title back. Reading through different questions I assumed it should have to do with fields in my search, but that doesn't change the response. I also tried using the _source-attribute, but no luck.


Solution

  • You can use:

    select_v2: ["title"], load: false