简体   繁体   中英

ElasticSearch / Tire - Facets are not filtered by the query?

I have an ElasticSearch / Tire query that has facets attached. It seems the facets a using the global scope, instead of the query scope and filters.

Here is my definition. I'm not sure how to scope the it to use the filters.

 def self.facets_for(keyword_array, fasit, opts = {})
    keyword_array = [keyword_array] if keyword_array.is_a?(String)
    tire.search(per_page: opts[:per_page], page: opts[:page] ) do 
      query do 
        boolean { should { string '*' }}
      end
      filter :terms, :keyword => keyword_array

      facet "phrases" do terms :phrases, :size => 20 end if fasit.include?("phrases")
      facet "sentiment" do terms :sentiment end if fasit.include?("sentiment")
      facet "lang" do terms :lang end if fasit.include?("lang")
      facet "provider" do terms :provider end if fasit.include?("provider")

    end # tire search
  end 

Right now, this returns facets that are "global" in scope, ie they aren't filtered by the filters (or the query if there is a more sophisticated query).

What am I missing?

Facets are by default bound (restricted) by the query issued: see the Tire integration test case .

Filters, on the contrary, do not restrict the facets, making "faceted navigation" possible (again, see the integration test case ).

Note that in your example, your query is effectively a match_all query, and thus cannot restrict facets.


On the Ruby side of things, a safer construct for keyword_array would be:

keyword_array = Array(keyword_array)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM