Guest User

Untitled

a guest
Jul 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. for (String fromIndex : indexList) {
  2. SearchResponse rsp = client.prepareSearch(fromIndex).
  3. setQuery(QueryBuilders.matchAllQuery()).setSize(hitsPerPage).
  4. // This is important:
  5. setSearchType(SearchType.QUERY_AND_FETCH).
  6. setScroll(TimeValue.timeValueMinutes(30)).execute().actionGet();
  7. try {
  8. long total = rsp.hits().totalHits();
  9. Collection<MyTweet> tweets = collectTweets(rsp);
  10. bulkUpdate(tweets, intoIndex);
  11. int page = 1;
  12. int pages = (int) (total / hitsPerPage);
  13. if (total % hitsPerPage > 0)
  14. pages++;
  15.  
  16. int collectedResults = 0;
  17. int currentResults;
  18. while ((currentResults = rsp.hits().hits().length) > 0) {
  19. collectedResults+=currentResults;
  20. rsp = client.prepareSearchScroll(rsp.scrollId()).
  21. setScroll(TimeValue.timeValueMinutes(30)).execute().actionGet();
  22. tweets = collectTweets(rsp);
  23. bulkUpdate(tweets, intoIndex);
  24. logger.info("Progress " + page++ + "/"+ pages + " current=" + currentResults
  25. + " total=" + total + " fromIndex=" + fromIndex);
  26. }
  27. logger.info("Finished copying of index:"+fromIndex+". Total:" + total + " collected:" + collectedResults);
  28. } catch (Exception ex) {
  29. logger.error("Failed to copy data from index " + fromIndex + " into " + intoIndex + ".", ex);
  30. }
  31. }
Add Comment
Please, Sign In to add comment