Facets counters

ruby
rails
facets
#1

Hi !
I would like to get facet counters in a bit more complicated usecase. For example we have 2 facets:

  • country_subdivision
  • property_type

For example when we search with:

{
    country_subdivision => 'NY',
    property_type => 'House'
}

we get only counters for those facet values (something like this):

{
  country_subdivision => {
    'NY' => 1
  },
  property_type => {
    'House' => 1
  }
}

In ES we had something like this (and we could give option for users to easily change the US state):

{
  country_subdivision => {
    'NY' => 1,
    'CA' => 1,
  },
  property_type: {
    'House' => 1,
    'Condo' => 1
  }
}

Do I think correctly that the only way to do this is to do multiple queries with removed filters ?

#2

Hi @j_e,

If I understand your question correctly, you would like to retrieve all facet counts.

To do this you can run a search and use the facets option with the asterisk wildcard:

index.search({
  query: '',
  facets: ['*'],
})

If you want to limit the counts for just a few of the facets, then name them specifically:

index.search({
  query: '',
  facets: ['country_subdivision','property_type'],
})

In the response, you can inspect the facets key for the value of all the facets and associated counts.

I hope this helps!

#3

Thanks for the response !
But unfortunately it does not help.
When I check the facets I only have count for country_subdivision set in facetFilters and I would like to get also info about other permutations of filters. Like without country_subdivision selected and so on.