
您可以这样做:
Client client;try { client = TransportClient.builder().build(). addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300)); QueryBuilder qb = QueryBuilders.boolQuery().mustNot(QueryBuilders.termQuery("user_agent", "")); SearchResponse scrollResp = client.prepareSearch("demo_risk_data") .addSort(SortParseElement.DOC_FIELD_NAME, SortOrder.ASC) .setScroll(new Timevalue(60000)) .setQuery(qb) .setSize(100).execute().actionGet(); //Scroll until no hits are returned while (true) { //Break condition: No hits are returned if (scrollResp.getHits().getHits().length == 0) { break; } // otherwise read results for (SearchHit hit : scrollResp.getHits().getHits()) { JSonObject value = new JSonObject(searchData.getSource()); System.out.println(value.toString()); } // prepare next query scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new Timevalue(60000)).execute().actionGet(); }}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)