相关疑难解决方法(0)

使用Java API从Elasticsearch获取所有记录

我试图使用Java API从Elasticsearch获取所有记录.但我收到以下错误

n [[Wild Thing] [localhost:9300] [indices:data/read/search [phase/dfs]]]; 嵌套:QueryPhaseExecutionException [结果窗口太大,+大小必须小于或等于:[10000]但是[10101].

我的代码如下

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());
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

目前本记录总数是131881,所以我开始from = 1to = 100再拿到100个记录,直到from <= 131881.有没有办法在Elasticsearch中没有其他记录,我可以检查以100的集合获取记录.

java elasticsearch

4
推荐指数
1
解决办法
5356
查看次数

标签 统计

elasticsearch ×1

java ×1