appbaseio / reactivesearch

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

Export query result to a file? #334

Closed knguyen0105 closed 6 years ago

knguyen0105 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

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

knguyen0105 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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

metagrover commented 6 years ago

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!