2
我想從使用Java API的Elasticsearch獲取所有記錄。但我收到以下錯誤使用Java API獲取Elasticsearch的所有記錄
n [[Wild Thing] [localhost:9300] [indices:data/read/search [phase/dfs]]]; 嵌套:QueryPhaseExecutionException [結果窗口太大,從 +大小必須小於或等於:[10000],但是[10101]。
我的代碼低於當前存在的有131881條記錄
Client client;
try {
client = TransportClient.builder().build().
addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
int from = 1;
int to = 100;
while (from <= 131881) {
SearchResponse response = client
.prepareSearch("demo_risk_data")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setFrom(from)
.setQuery(QueryBuilders.boolQuery().mustNot(QueryBuilders.termQuery("user_agent", "")))
.setSize(to).setExplain(true).execute().actionGet();
if (response.getHits().getHits().length > 0) {
for (SearchHit searchData : response.getHits().getHits()) {
JSONObject value = new JSONObject(searchData.getSource());
System.out.println(value.toString());
}
}
}
}
總數,所以我開始from = 1
和to = 100
,然後得到100個記錄,直到from <= 131881
。有沒有辦法讓我可以檢查獲得100條記錄的記錄,直到Elasticsearch中沒有進一步的記錄爲止。
完美,太感謝你了 –