Build Elasticsearch/OpenSearch search bodies with Jbuilder instead of nested Ruby hashes. Plays nicely with Esse out of the box.
Contents
What you get
- Use Jbuilder blocks directly inside
UsersIndex.search { |json| ... }. - Render
.json.jbuildertemplate files fromapp/searches/. - Works across multiple indices (
Esse.cluster.search(Index1, Index2) { |json| ... }).
Quick start
# Gemfilegem 'esse', '>= 0.2.4'gem 'esse-jbuilder'# Inlineresults = UsersIndex.search do |json| json.query do json.match do json.set! 'name', params[:q] end endend
# From a template file (Rails only)body = Esse::Jbuilder::ViewTemplate.call('users/search', q: params[:q])results = UsersIndex.search(body: body)Configuration
One option:
Esse.configure do |config| config.search_view_path = 'app/searches' # defaultendVersion
- Version: 0.0.5
- Ruby:
>= 2.5.0 - Depends on:
esse >= 0.2.4,jbuilder >= 2
License
MIT.