# Ruby: Faceted navigation in a Rails app

**URL:** <https://discuss.elastic.co/t/ruby-faceted-navigation-in-a-rails-app/42924>\
**Category:** Elasticsearch\
**Created:** [February 27, 2016, 6:57pm UTC](https://discuss.elastic.co/t/ruby-faceted-navigation-in-a-rails-app/42924 "2016-02-27T18:57:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![renzokuken](https://avatars.discourse-cdn.com/v4/letter/r/aca169/32.png) [@renzokuken](https://discuss.elastic.co/u/renzokuken)\
**Post date:** [February 27, 2016, 6:57pm UTC](https://discuss.elastic.co/t/ruby-faceted-navigation-in-a-rails-app/42924/1 "2016-02-27T18:57:03Z")

</div>

Hello.

I have an online store built with Ruby on Rails, where I want to index my products' specs/attributes and then provide filtering options to my users.

I'm in the process of figuring out how I will build my queries, and I want some help.

I'm using the elasticsearch-model gem, with which I can do queries like this:

`Product.search(filter: { bool: { filter: [{term: {category_id: 7}}, {range: {price: {gte:51.5, lte: 60}}}]} })`

meaning "give me all products from category X that are in the following price range".

1. The query above returns the proper results, but is it the way to go or I can write this in a more idiomatic/correct way?

2. I'm thinking about how should I _build_ compound queries like this in an imperative fashion, based on input that user has given me (through query string params in the URL or something).

Should I use the elasticsearch-dsl gem or I can do this by just constructing the hashes my own?

1. I tried to convert that query using the elasticsearch-dsl gem but failed to do so:

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:13pm UTC](https://discuss.elastic.co/t/ruby-faceted-navigation-in-a-rails-app/42924/2 "2017-07-05T23:13:06Z")

</div>


