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

Export query result to a file? #334

Closed
knguyen0105 opened this issue Apr 19, 2018 · 10 comments
Closed

Export query result to a file? #334

knguyen0105 opened this issue Apr 19, 2018 · 10 comments

Comments

@knguyen0105
Copy link

Is it possible to export a query result to a file?

I'm working on a search feature for our customer database. One requirement is that users can export a search result to a csv file so that it can be forwarded to another team (i.e marketing).

How do I implement this with reactivesearch? Thanks

@davidklebanoff
Copy link

davidklebanoff commented Apr 19, 2018

It seems to me you would want to hook into the onAllData property of your result component to retrieve the search result data and from there you can perform your custom logic to generate a csv file.

@siddharthlatest
Copy link
Member

@knguyen0105 What @davidklebanoff is suggesting should work. There is one caveat (that I can think of) - your max export size (due to the result size cap in Elasticsearch) will be up to 1000 results.

@davidklebanoff
Copy link

davidklebanoff commented Apr 19, 2018

@siddharthlatest - For clarity, are you referring to the index.max_result_window on the Elasticsearch server? If so, you may be missing a 0, because the default value for that setting 10000. The value can be raised even further via your ElasticSearch settings, at your own risk of course.

@siddharthlatest
Copy link
Member

@davidklebanoff You're right :-), it's 10000.

@knguyen0105
Copy link
Author

Thanks much @davidklebanoff and @siddharthlatest.

What if we need to export upto 1M records? What are the risks if we modify the Elastic settings? One workaround I can think of is to save the query (not the query result) to run it later on the terminal where I have more flexibility, Would it work?

@davidklebanoff
Copy link

@knguyen0105 That sounds like a question best suited for ElasticSearch. Have you tried looking at the ElasticSearch documentation, Google, or Elasticsearch forums?

Remember, ReactiveSearch is just a React-based UI for Elasticsearch. Outside of the user interface and the query building logic, the core of the work is being done by Elasticsearch.

@knguyen0105
Copy link
Author

@davidklebanoff : My apology if the question seems irrelevant. I just tried reactivesearch and elasticsearch a few days ago.

Maybe I wasn't clear. My question is can I retrieve the query being sent to elasticsearch from ResultList component. My end-users (non-tech) will have a button 'Save Query' when there are more than 10k records. The user will "Save Query" and forward it to tech support later.

@metagrover
Copy link
Contributor

Hi @knguyen0105

If you are dealing with large sets of data, you'll have to determine the active query on the results component via onQueryChange and then perform paginated requests to the elasticsearch cluster and keep feeding the results from the query (paginated) hits.

(I will attach a code snippet to achieve this sometime later today).

@knguyen0105
Copy link
Author

Thank you @metagrover . A code sample defintely will help a lot.

@metagrover
Copy link
Contributor

Snippet for exporting query hits data as csv can be found here. 🎉

@knguyen0105 Please try it out and let me know if that works for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants