Disjunctive facets using the javascript app search client

Hi!

I am facing some issues with the javascript client of app search and maybe you can help me.

I have an engine with documents loaded into elastic and now I'm playing with this js client to fetch the data.

I created 4 facets and I want to perform a query filtering by one of them. As a result, I want to receive all the facets, even if there are no results for any of them.

To do that I read the guide of the client in GitHub and I ran into the disjunctiveFacets option.

As far as I understand, if you include the 4 facets into a String array two queries will be performed, one returning the filtered results and another one retrieving all the facets in the disjunctive array. am I right?

Currently, the facet query only retrieves the facets for the field I am filtering and I need to have them all.

this is the options object I am building right now:

    const options = {
      facets: {
        creator: {
          type: 'value',
          size: 100,
        },
        name: {
          type: 'value',
          size: 100,
        },
        stage: {
          type: 'value',
          size: 100,
        },
        assignee: {
          type: 'value',
          size: 100,
        },
      },
      filters: {
        any: [
          {
            creator: 'whatever',
          },
        ],
      },
      disjunctiveFacets: ['creator', 'name', 'stage', 'assignee'],
      result_fields: { //truncated},
      page: {
        size: 20,
        current: 1,
      },
    };

Thank you very much in advance!

Hey Pablo!

So disjunctive faceting works a little different than what you're expecting here.

It specifically only comes into play when you select a filter value that corresponds to a facet. It returns all of the available facets as if that filter was NOT applied.

However, it won't return ALL facets. The facets shown are still based on the underlying results... so if you've queried on the text "foo", you're still only going to see facets that are applicable to the results for the underlying query "foo".

You' have to do an empty query (empty meaning a query with an empty string as the query text) which fetches facets. You'd build a facet filter based off of that and then not recalculate it on each query. You would calculate those facets just one time when you load the application.

Hopefully that makes sense. Just let me know if I need to clarify anything.

Yes, now it's totally clear for me :slight_smile: thank you very much.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.