Note that there are some explanatory texts on larger screens.

plurals
  1. POMixing conditional operators with facets in Elasticsearch
    primarykey
    data
    text
    <p>I am trying to match a search query against two fields, as well as filter by facets if selected from dropdowns on the page.</p> <p>When the user enters keywords it should match if found in two database fields: Title and Description. The dropdowns filter by a status, and a type. </p> <p>Here is my Tire search configuration:</p> <pre><code> def self.search(params) tire.search(load: true, page: params[:page], per_page: 25) do query do boolean do should { string "title:#{params[:query]}", default_operator: "OR" } if params[:query].present? should { string "description:#{params[:query]}", default_operator: "OR" } if params[:query].present? must { term :status_id, params[:status_id] } if params[:status_id].present? must { term :type_id, params[:type_id] } if params[:type_id].present? end end sort { by :updated_at, "desc" } if params[:query].blank? facet "status" do terms :status_id end facet "type" do terms :type_id end end end </code></pre> <p>Indexing settings:</p> <pre><code> settings :analysis =&gt; { :filter =&gt; { :my_ngram =&gt; { "type" =&gt; "nGram", "max_gram" =&gt; 10, "min_gram" =&gt; 3} }, :analyzer =&gt; { :my_analyzer =&gt; { "type" =&gt; "custom", "tokenizer" =&gt; "lowercase", "filter" =&gt; ["my_ngram"] } } } do mapping do indexes :title, boost: 10, analyzer: 'my_analyzer' indexes :description, boost: 5, analyzer: 'my_analyzer' indexes :status_id, :type =&gt; 'integer' indexes :type_id, :type =&gt; 'integer' end end </code></pre> <p>I originally only had the title and description fields, which was working fine. I am now trying to add the ability to filter by status and type. </p> <p>What is the proper way to configure this? If status is selected, it should only return records with that status. The same follows for type, and if both are selected.</p> <p>Any help is appreciated.</p> <p>It's not that errors occur, but the results no longer filter at all by either keywords or facets:</p> <pre><code>curl -X GET 'http://localhost:9200/projects/project/_search?load=true&amp;size=25&amp;pretty' -d '{"query":{"bool":{"should":[{"query_string":{"query":"title:test","default_operator":"OR"}},{"query_string":{"query":"description:test","default_operator":"OR"}}],"must":[{"term":{"status_id":{"term":"1"}}},{"term":{"type_id":{"term":"1"}}}]}},"facets":{"status":{"terms":{"field":"status_id","size":10,"all_terms":false}},"type":{"terms":{"field":"type_id","size":10,"all_terms":false}}},"size":25}' # 2013-08-16 12:08:34:791 [200] (31 msec) # # {"took":31,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]},"facets":{"status":{"_type":"terms","missing":0,"total":0,"other":0,"terms":[]},"type":{"_type":"terms","missing":0,"total":0,"other":0,"terms":[]}}} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload