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.9k stars 367 forks source link

[ElasticSearch] SearchTerm is ignored when adding a predefined filter to the search-ui config #892

Open ZakKa89 opened 1 year ago

ZakKa89 commented 1 year ago

Describe the bug SearchTerm is ignored when adding a predefined filter to the search-UI config. So doesn't matter what you search on, the search will just return the items from the predefined filters.

To Reproduce

  1. add filter to the searchQuery object for example"
    searchQuery: {
    filters: [{ field: "id", type: "all", values: ["park_acadia"]}],

https://codesandbox.io/s/github/elastic/search-ui/tree/master/examples/sandbox?file=/src/pages/elasticsearch/index.js:1108-1121

Note that for App Search this works fine!

  1. search for a value that you know will not give any results like ///\\/\/\/\/\/\/\//\\\

You will see that you will still get the result of the filter...

Expected behavior

Which backends and packages are you using: Backend: [Elastic Search cloud]

"@elastic/react-search-ui": "^1.17.1",
"@elastic/react-search-ui-views": "^1.17.1",
"@elastic/search-ui": "^1.17.1",
"@elastic/search-ui-elasticsearch-connector": "^1.17.1",
JasonStoltz commented 1 year ago

Good catch, I appreciate the bug report.

JasonStoltz commented 1 year ago

@ZakKa89 If you want to help us fix any of this... we are hiring :)

RobbyUitbeijerse commented 1 year ago

hi there! Not sure if related, but we came to an interesting situation and it feels like the right issue to post this in.

The filter we are applying looks like this:

      filters: [
        {
          field: 'owner.keyword',
          values: [userAddress],
          type: 'all' as const,
        },
      ],

Within the input that you can see in the video below, we would would like to allow users to further specify the results they are seeing by allowing them to set a search term on top of the pre-defined filters in the config. Just to clarify, this is the handler for setting the search term:

        onChange={e => setSearchTerm(e.target.value)}

Combining this, we do actually see that setSearchTerm seems to be working, but it seems to sort the results rather than filtering out results that can be considered irrelevant by setting the searchTerm. Please note that the items you see in the video is the subset of our total index based on the pre-defined filters.

https://user-images.githubusercontent.com/10176709/199464191-987406c7-f335-4ab0-9e50-cbec45e77ac1.mp4

I've tried to debug the query that gets sent over to Elastic by logging the request body. The interesting part is that setting the search term (and filters) client side through the input onChange leads to quite a bit of a different query compared to the an initial query where filters + a search term is applied

ZakKa89 commented 1 year ago

we would would like to allow users to further specify the results they are seeing by allowing them to set a search term on top of the pre-defined filters in the config

@RobbyUitbeijerse Your question is probably not related to my issue, but there's a difference between global filters (predefined) and filters for the user in the search UI config. The filters for the user are defined in the 'facets' object. I don't think you're using that. So I suggest to dive into the Facets configuration part of search-ui

TLDR: You will need to add the filters that the user has control of to the config of Search-UI within the facets object

Mites-G commented 1 year ago

hi there! Not sure if related, but we came to an interesting situation and it feels like the right issue to post this in.

The filter we are applying looks like this:

      filters: [
        {
          field: 'owner.keyword',
          values: [userAddress],
          type: 'all' as const,
        },
      ],

Within the input that you can see in the video below, we would would like to allow users to further specify the results they are seeing by allowing them to set a search term on top of the pre-defined filters in the config. Just to clarify, this is the handler for setting the search term:

        onChange={e => setSearchTerm(e.target.value)}

Combining this, we do actually see that setSearchTerm seems to be working, but it seems to sort the results rather than filtering out results that can be considered irrelevant by setting the searchTerm. Please note that the items you see in the video is the subset of our total index based on the pre-defined filters.

setSearchTerm.mp4 I've tried to debug the query that gets sent over to Elastic by logging the request body. The interesting part is that setting the search term (and filters) client side through the input onChange leads to quite a bit of a different query compared to the an initial query where filters + a search term is applied

My team is facing this issue as well. Have you found a solution or workaround for this?

Mites-G commented 1 year ago

Just giving context on my previous comment. Not related to OP's issue.

Elasticsearch connector's requestBody query uses this should property which seems to cause this behaviour. image If you force change it to must through customizing ES connector, the issue seems to be resolved.

For some reason this is only relevant when global filters are applied through configuration.

Scientist-Ansh commented 7 months ago

@ZakKa89 If you want to help us fix any of this... we are hiring :)

The searchTerm is still ignored if there is a global filter present.

joemcelroy commented 7 months ago

thanks, will put this under buglist. Happy to accept a PR for this too :)