Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ZakKa89 opened this issue Oct 28, 2022 · 8 comments
Labels
bug Something isn't working elasticsearch-connector pinned tracking Adding issue to project board

Comments

@ZakKa89
Copy link

ZakKa89 commented Oct 28, 2022

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 ZakKa89 added the bug Something isn't working label Oct 28, 2022
@ZakKa89 ZakKa89 changed the title SearchTerm is ignored when adding a predefined filter to the search-ui config [ElasticSearch] SearchTerm is ignored when adding a predefined filter to the search-ui config Oct 28, 2022
@JasonStoltz
Copy link
Member

Good catch, I appreciate the bug report.

@JasonStoltz
Copy link
Member

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

@RobbyUitbeijerse
Copy link

RobbyUitbeijerse commented Nov 2, 2022

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

@ZakKa89
Copy link
Author

ZakKa89 commented Nov 11, 2022

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
Copy link

Mites-G commented Dec 1, 2022

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
Copy link

Mites-G commented Dec 2, 2022

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
Copy link

Scientist-Ansh commented Jan 17, 2024

@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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working elasticsearch-connector pinned tracking Adding issue to project board
Projects
None yet
Development

No branches or pull requests

7 participants