Elasticsearch

Elasticsearch,第1张

Elasticsearch

尝试按照以下示例 *** 作,我正在使用此代码,它可以正常工作:

        String query = "your query here";        QueryBuilder matchQueryBuilder = QueryBuilders.boolQuery().must(new QueryStringQueryBuilder(query));        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();        searchSourceBuilder.query(matchQueryBuilder);        searchSourceBuilder.size(5000); //max is 10000        searchRequest.indices("your index here");        searchRequest.source(searchSourceBuilder);        final Scroll scroll = new Scroll(Timevalue.timevalueMinutes(10L));        searchRequest.scroll(scroll);        SearchResponse searchResponse = client.search(searchRequest); String scrollId = searchResponse.getScrollId();        SearchHit[] allHits = new SearchHit[0];        SearchHit[] searchHits = searchResponse.getHits().getHits();        while (searchHits != null && searchHits.length > 0)        { allHits = Helper.concatenate(allHits, searchResponse.getHits().getHits()); //create a function which concatenate two arrays SearchScrollRequest scrollRequest = new SearchScrollRequest(scrollId); scrollRequest.scroll(scroll); searchResponse = client.searchScroll(scrollRequest); scrollId = searchResponse.getScrollId(); searchHits = searchResponse.getHits().getHits();        }        ClearScrollRequest clearScrollRequest = new ClearScrollRequest();        clearScrollRequest.addScrollId(scrollId);        ClearScrollResponse clearScrollResponse = client.clearScroll(clearScrollRequest);


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4899318.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存