Efficient way to calculate * Boundary of faces * in elastic search

I want to calculate the number of facets for the facet query user interface, but I think I'm missing something because I cannot get the numbers I need using facet filters.

Here is an example. Given two facets with three possible terms in each aspect:

Colors: {red, yellow, blue} Notes: {do, re, mi} 

When I search, the calculations for each term in the facet do not take into account the filters set in another aspect.

To illustrate:

 [ ] All colors (18) [x] Red (10) [ ] Green (5) [ ] Blue (3) [ ] All notes (18) [ ] Do (5) [x] Re (7) [ ] Mi (6) 

Note that the totals in each facet are summed with the total number of queries for the query, as if filters had not been set.

The behavior I want is the number on the Notes facet that takes into account the filter in the Colors column and vice versa. That is, the numbers for the conditions of the note must be added up to 10 (to match the red filter), and not 18.

Interestingly, the screenshot example in the docs uses the Linked In example, which actually demonstrates the behavior I want.

http://www.elasticsearch.org/guide/reference/api/search/facets/

I can get the result I want by restarting the query once for each term in each aspect (ugh), but I wonder if there is a way to get the same behavior as LinkedIn from the box by changing my query.

+3
source share
1 answer

The only way I found this is to use the following logic for any multi-faceted facet:

Whenever the user selects a value from the facet ("drill down"), you add the appropriate filter to all faces (via facet_filter) except the face to which the selection was made, as well as to the top-level filter to filter the query results.

In other words, given 3 multi-screen faces, A, B, and C:

  • Select a value from A => Add Filter to the top level filter , as well as to facet_filter faces B and C.
  • Select a value from B => Add filter to the top level filter , as well as facet_filter from A and C.
  • ... etc.

The top-level filter always combines filters for all selections, while each individual facet contains facet_filters according to the selection in other faces.

+7
source

Source: https://habr.com/ru/post/976467/


All Articles