ElasticSearchã§ããã°ãã¼ã¿éè¨ã試ã¿ã¦å°ã£ãç¹ãã®ï¼ï¼Java APIã§ä½åãæ¥ç¶ã«è¡ã£ã¦ãããNoNodeAvailableExceptionã§è½ã¡ã
åã«ãæ¸ããã®ã§ãããElasticSearchã¯ã¾ã æ¥æ¬èªã®æ å ±ãå°ãªããã¯ã¾ã£ãæã«ããé¢åã¨ããã®ãç§ã®ææã§ããElasticSearchã使ã£ã¦1000ä¸ä»¶ãããã®ãã¼ã¿ã®éè¨ããããã¨è©¦ã¿ã¦ããã¤ãå°ã£ãç¹ããã£ãã®ã§ãæ¥æ¬èªã®æ å ±ãç¡ãããã ã£ãç©ã ãåå¿é²ã¨ãã¦æ®ãã¦ããã¾ããè¨èªã¯Javaã§ããPythonã¯è¦æã§ãã
ã¾ãã1000ä¸ä»¶ã®ãã¼ã¿ããã£ãºãã«å¼ã£å¼µã£ã¦ããã¨å½ç¶ã¡ã¢ãªã足ããªãã¦è½ã¡ãã®ã§ã以ä¸ã®ãããªã³ã¼ãã§10ä¸ä»¶ãã¤åã£ã¦ããããã«ãã¾ããã
//ã¾ãAggregationã¯ã¨ãªã§å ¨ä½ã®ä»¶æ°ç¢ºèª StatsBuilder aggregation = AggregationBuilders.stats("agg").field("id"); SearchRequestBuilder searchReq = client.prepareSearch("index_name"); searchReq.setTypes("test"); searchReq.setSize(0); searchReq.addAggregation(aggregation); SearchResponse searchRes = searchReq.execute().actionGet(); Stats stats = searchRes.getAggregations().get("agg"); long docCount = stats.getCount(); int offset = 0; int rows = 100000; while(true) { SearchRequestBuilder searchReq = client.prepareSearch("index_name"); searchReq.setTypes("test"); searchReq.setSize(rows); searchReq.setFrom(offset); searchReq.setQuery(QueryBuilders.matchAllQuery()); SearchResponse searchRes = searchReq.execute().actionGet(); for(Iterator<SearchHit> itr = searchRes.getHits().iterator(); itr.hasNext();) { //éè¨å¦ç offset++; } if (offset > docCount) { break; } }
ããã¨ãéè¨ã®éä¸ï¼ã ããã800ä¸ä»¶ãããï¼ã§NoNodeAvailableException:No node availableã§è½ã¡ãäºè±¡ãé »çºãã¾ããã
â»ElasticSearchã«ãã¼ããã©ã¯ã¼ãã£ã³ã°ã§èãã«è¡ã£ã¦ããã®ã主åå ããããã¾ããããä»åã¯ããã¯å¤æ´ã§ããªãã£ãã®ã§ãä»ã®å¯¾å¦çãèãã¾ããã
çµå±ãsearchReq.execute().actionGet();ãå¼ã¶æã«NoNodeAvailableExceptionãæ¾ã£ããä¸å®æéã¹ãªã¼ãããã¨ããåç´ãªæ¹æ³ã§ä¸å¿è§£æ±ºãã¾ããããã£ã¨ã¹ãã¼ããªããæ¹ããã¾ãããæãã¦ãã ããã
SearchResponse searchRes; while (true) { try { searchRes = searchReq.execute().actionGet(); break; } catch (NoNodeAvailableException cont) { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } continue; } }
ElasticSearchã®Java APIã®æ¥æ¬èªè¨äºãã»ã¨ãã©ç¡ãæ°ããã¦å°ã£ã¦ãã¾ããçããä½ã§ãããã¦ããã§ããããï¼