I assume that you have an available and working instance of ElasticSearch. If you want to use queries with nested objects, you need to use the interfaces provided by chewygem ie Define a custom index field. Here is an example from the vanilla documentation . First of all you need to create/app/chewy/article_index.rb
class ArticleIndex < Chewy::Index
define_type Article.published.includes(:author_name) do
field :title, :body
field :author_name, value: ->(article) { "#{article.author.first_name} #{article.author.last_name}" }
end
end
Now request it as:
UsersIndex.query(text: {author_name: 'John'})
# or
UsersIndex.query(text: {author_name: 'Smith'})
# or even ...
UsersIndex.query(text: {author_name: 'John Smith'})
Other readings:
Hurrah!
source
share