3
回答
ES中存储的数据量为100万条,当根据条件查询ES中符合条件的所有数据时,ES查询速率很慢,需要一分多钟。那么请问在这种情况下,怎样才能提高ES的查询效率呢?
科大讯飞通用文字识别100000次/天免费使用。立即申请   

根据条件查询es中符合条件的所有数据的java核心代码如下所示:

QueryBuilder queryBuilder_01 = rangeQuery("age").gt(Integer.parseInt("20")); 
QueryBuilder queryBuilder_02 = rangeQuery("income_month").gt(Double.parseDouble("10000")); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(queryBuilder_01);
boolQueryBuilder.must(queryBuilder_02);

List<Customer> customers = new ArrayList<>();
SearchResponse response = client.prepareSearch(customerIndex)
        .setTypes(customerType)
        .setScroll(TimeValue.timeValueMinutes(1))
        .setQuery(boolQueryBuilder)
        .setSize(1000)
        .get();
do {
    customers = getCustomers(customers,response);
    response = 
client.prepareSearchScroll(response.getScrollId()).setScroll(TimeValue.timeValueMinutes(1)).execute().actionGet();
} while(response.getHits().getHits().length != 0);

 

<无标签>
举报
liao168
发帖于10个月前 3回/266阅
顶部