elastic / search-ui

Search UI. Libraries for the fast development of modern, engaging search experiences.
https://docs.elastic.co/search-ui
Apache License 2.0
1.91k stars 368 forks source link

Facet filterType="none" doesn't translate to a must_not filter in Elasticsearch Connector query #783

Open rodeinator opened 2 years ago

rodeinator commented 2 years ago

We tested the Facet component with filterType="none". But it doesn't translate to a must_not filter in Elasticsearch query.

<Facet
  field="comics"
  label="Comics"
  filterType={"none"}
  view={MultiCheckboxFacet}
/>

Resulting request query:

"filter" => [
  %{"bool" => %{"must" => [%{"term" => %{"comics" => "Batman"}}]}}]

When we set a filter in config.filters the query uses must_not as expected

filters: [
      { field: "comics", values: ["Batman"], type: "none" }
]

Resulting request query:

"filter" => [
   %{"bool" => %{"must_not" => [%{"term" => %{"comics" => "Batman"}}]}}
]
joemcelroy commented 2 years ago

Thanks so much for the bug report. will get back to you.

botelastic[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Is this issue still important to you? If so, please leave a comment and let us know. As always, thank you for your contributions.

cingram16 commented 2 years ago

+1 in need of this capability.

Any plans to work this issue?

fa11enangel commented 2 years ago

An other solution would be to build up a second data structure, where all not selected/saved/set data fields would be saved and query these for existance, if something should not have it.

An example for movies and genres would be: The Matrix

Something like "all comedies which are not anime":

filters: [
        {
          field: 'genre',
          type: 'all',
          values: ['comedy'],
        },
        {
          field: 'not_genre',
          type: 'all',
          values: ['anime'],
        },
],
RobbyUitbeijerse commented 1 year ago

We ran into a similar issue where we tried to pass 'none' as a filter in the provider config for a specific page, but type: 'none' gives us no results at all, while type: 'all' returns the exact item we want to exclude (so that at least confirms that the data is good)

here is a snippet:

      filters: [
        {
          field: 'address.keyword',
          type: 'none',
          values: [contractAddress],
        },
      ],

Could it be that that the transformation in the connector package doesn't actually build up a query that is usable for elastic? I don't have the thorough experience with Elastic yet to confirm it based on what I'm seeing here:

https://github.com/elastic/search-ui/blob/master/packages/search-ui-elasticsearch-connector/src/handlers/search/Configuration.ts

filipefborba commented 1 year ago

Can confirm that adding a filter with type "any" (should) or "none" (must_not) doesn't work. It always defaults to "all" (filter). This is definitely a bug.