appbaseio / reactivesearch

Search UI components for React and Vue
https://opensource.appbase.io/reactivesearch
Apache License 2.0
4.89k stars 470 forks source link

Issuing searches by search template id. #314

Closed timtutt closed 4 years ago

timtutt commented 6 years ago

Issue Type: Enhancement

Platform: Web (but this could apply for both)

Description: Would like to be able to issue a search using a stored search template passing the template id and parameters. Implementing this within the ReactiveComponent would likely be the most ideal place.

Screenshots:

Minimal reproduction of the problem with instructions: N/A

Reactivesearch version: x.y.z latest

Browser: ALL

Anything else:

Example of query from ES Website: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html

GET _search/template
{
    "id": "<templateName>", 
    "params": {
        "query_string": "search for these words"
    }
}
timtutt commented 6 years ago

This would actually be really easy if a "endpoint" parameter was exposed. The only thing I'd need to be able to do is append "/template" tot he "/_search" endpoint.

siddharthlatest commented 6 years ago

@timtutt You bring up a great point. Currently, we are thinking to expose a beforeQueryChange prop to each component which provides all the context around the query that ReactiveSearch creates, that can be potentially used to then change the query body as well as the endpoint URI, headers to send the request.

It's still in ideation phase, as we are thinking through the cases it can handle. Do you think this can be a good way to handle passing down the templates?

timtutt commented 6 years ago

@siddharthlatest - yes I think this could solve it in my case, although it's a little more complex of a solution as someone would be required to implement all of the logic for modifying the endpoint URI for each template the wanted to implement for. I could definitely work with in this framework...

That said - I think for an easier experience exposing a search_template_id parameter along with search_template_params (search_template_id being required to use this) would be the more ideal solution.

siddharthlatest commented 6 years ago

@timtutt Out of curiosity, what's a good use-case you are seeing for using templates over the queries generated by RS?

timtutt commented 6 years ago

@siddharthlatest - in my specific use case, I've used ReactiveComponent to create charts. Right now I'm creating the default query on the fly as a part of the components themselves, but would prefer to have search templates stored in ES and only pass the parameters.

The queries for charts that I'm generating are date histogram stats, terms aggregations, etc...

davidklebanoff commented 6 years ago

@siddharthlatest, @timtutt - Perhaps templates could be considered more secure for some scenarios? I've never personally used templates, so I'm not terribly familiar, but if an ES server could be locked down to only allow templates to run, then I imagine that would greatly eliminate potential avenues of abuse.

siddharthlatest commented 6 years ago

@davidklebanoff That is true. Templates ensure one can't run injections (since you only pass allowed params to the server) and solve the abuse problem quite effectively.

We plan to look into how to support this after the v2.4 (next) release.

timtutt commented 6 years ago

any updates on this? Still on the backlog?

getorca commented 5 years ago

any updates on this? I'm looking for the same ability to use templates.

siddharthlatest commented 5 years ago

@getorca It's possible to do this now but requires some work on a user's end. We support transformRequest prop in ReactiveBase which allows changing the endpoint, headers and request body. You would ideally keep a state of current components' values and use them as param values to pass in instead of the generated query.

Let me know if this helps! And if you have any ideas on how can make this easier to use, we will consider it. :-)

stale[bot] commented 4 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. Thank you for your contributions.

epugh commented 9 months ago

Hi all, I was curious if there is any energy to look at this issue again? We use (and recommend ;-) ) the use of Templates in search, and would love to see this brought to ReactiveSearch. Specifically, we are using ReactiveSearch with Chorus for OpenSearch, and we want to demonstrate the differences between keyword search and vector search by swapping templates. I'm happy to talk more about pros/cons for Templates in general if there is interest ;-).