app-search-javascript icon indicating copy to clipboard operation
app-search-javascript copied to clipboard

Disjunctive facets may break when used with signed search keys

Open TCMiranda opened this issue 5 years ago • 13 comments

Hello! I'm having trouble to make disjunctive facets work with signed search keys.

I think it's related to this: https://github.com/elastic/search-ui/issues/347

On this line, I see that we are cleaning up request filters, but on my case filters are still sent this way: Screenshot from 2020-06-02 11-34-24

Which seems to cause some kind of issue with AppSearch using signed search keys.

  "alerts":[{"code":5001,"message":"Degraded search results","link":"https://swiftype.com/documentation/app-search/alerts#5001"}]

What I tried:

  • If I remove filters on that request it works even with a signed search key
  • Also if I change the signed search key to a normal search key, it also works.

One last thing My search key only applies one filter: Screenshot from 2020-06-03 15-32-39

Any help is much appreciated!! Thanks

TCMiranda avatar Jun 03 '20 18:06 TCMiranda

same problem here. Removing Disjunctive facets fixes the issue for the signed key. But how to make it work with Disjunctive facets ?

zenati avatar Jun 20 '20 08:06 zenati

Hey, I'm really sorry for the late response. I'm digging into this now.

JasonStoltz avatar Jul 30 '20 18:07 JasonStoltz

I set up a disjunctive faceting example in codesandbox to try to reproduce.

codesandbox.io/s/signed-search-key-issue-76quc

I can't quite reproduce what you are describing.

JasonStoltz avatar Jul 31 '20 17:07 JasonStoltz

Hi, seems right Jason. Are you sure there aren't differences between the backend on Swifttype and Appsearch 7.6.2?

TCMiranda avatar Aug 01 '20 16:08 TCMiranda

Also, about the syntax, I've used the one with "all" inside of it.

filters: { all: { world_heritage_site: 'true' } }

Instead of

filters: { world_heritage_site: 'true' }

TCMiranda avatar Aug 01 '20 16:08 TCMiranda

We have the same issue here on App Search version 7.9.1. Using a Signed Search Key with a single filter similar to @TCMiranda's example, the API returns "Degraded search results" because the filters are overridden when retrieving facets. Using a normal search key or a Signed Search Key without filters works correctly.

As a point of interest, I replicated these conditions using the Python lib and received the same results.

calitidexvii avatar Sep 21 '20 16:09 calitidexvii

@TCMiranda, have you found a workaround? The line you mentioned in your comment above seems promising. For example, if removing appliedDisjunctiveFilter results in no filters at all then removing filters from the search.

calitidexvii avatar Sep 23 '20 23:09 calitidexvii

Sorry no workaround. We are just not using it. We created a custom search component that aways show the options we want. We loose counter though.

TCMiranda avatar Sep 24 '20 00:09 TCMiranda

@TCMiranda I think you were right. We modified that function at line 174 to test whether the length of any is 0 and if so, delete it from filters. For our use-case, this makes everything work perfectly using a Signed Search Key with embedded filters. This is not a robust or recommended solution, so YMMV, but I think it at least provides a starting point. We'll try to develop this idea further and maybe @JasonStoltz can confirm whether this is the right direction.

var disjunctiveQueriesPromises = listOfAppliedDisjunctiveFilters.map(function (appliedDisjunctiveFilter) {
  var testFilters = filters.removeFilter(appliedDisjunctiveFilter).filtersJSON;
  if(testFilters.all[0].any.length == 0) {
    delete testFilters.all[0];
  }
  return _this._performSearch(_extends({}, params, {
    filters: testFilters,
    page: _extends({}, page, {
      // Set this to 0 for performance, since disjunctive queries
      // don't need results
      size: 0
    }),
    analytics: analytics,
    facets: defineProperty({}, appliedDisjunctiveFilter, params.facets[appliedDisjunctiveFilter])
  }));
});

calitidexvii avatar Sep 25 '20 10:09 calitidexvii

The Elastic engineers found the problem. It was actually on the back-end and not a fault of the app-search-javascript lib. The fix will be released in 7.9.3. I'll confirm once I have an opportunity to test the fix.

calitidexvii avatar Oct 01 '20 11:10 calitidexvii

I just tried it against 7.9.3 and it doesn't seem to be fixed yet.

adnan-i avatar Oct 23 '20 15:10 adnan-i

Confirmed, still receiving "Degraded search results" on 7.9.3.

The error, however, is fixed using Signed Search Keys with the Python lib, so I think there's another issue in the app-search-javascript lib.

calitidexvii avatar Oct 24 '20 12:10 calitidexvii

The issue was identified by support and a fix is planned for v7.11. Here are the details:

"Deeply nested empty filters are causing issues because they aren't caught by the filter.blank? check since they contain subfilters. This causes empty boolean queries to be sent to Elasticsearch, which returns errors.

This removes/ignores empty subfilters by recursively filtering them out in CompositeQueryFilter. It also has the side effect of normalizing nested filters by wrapping them as arrays.

The planned fix is to change the condition for overriding @all_subfilters with filter_definition because we think we only need to care about the case when it's a field name (not any/all/none). It should also prevent @all_subfilters from being reset if all of its subfilters happen to be empty."

calitidexvii avatar Dec 07 '20 15:12 calitidexvii