search-ui icon indicating copy to clipboard operation
search-ui copied to clipboard

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

Open ZakKa89 opened this issue 3 years ago • 8 comments
trafficstars

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

  • searchTerm must still work when having predefined filters

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",

ZakKa89 avatar Oct 28 '22 14:10 ZakKa89

Good catch, I appreciate the bug report.

JasonStoltz avatar Oct 31 '22 16:10 JasonStoltz

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

JasonStoltz avatar Oct 31 '22 16:10 JasonStoltz

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

RobbyUitbeijerse avatar Nov 02 '22 09:11 RobbyUitbeijerse

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

ZakKa89 avatar Nov 11 '22 12:11 ZakKa89

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?

too-soon avatar Dec 01 '22 10:12 too-soon

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.

too-soon avatar Dec 02 '22 20:12 too-soon

@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.

Scientist-Ansh avatar Jan 17 '24 08:01 Scientist-Ansh

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

joemcelroy avatar Jan 26 '24 10:01 joemcelroy