params){
246 | Client client = getClient().getClient();
247 | SearchRequestBuilder builder = client.prepareSearch(index).setTypes(types).setSearchType(SearchType.DFS_QUERY_AND_FETCH);
248 | builder.setVersion(true);
249 | buildQueryFiled(builder,params);
250 | SearchResponse response = builder.execute().actionGet();
251 | return response;
252 | }
253 | /**
254 | * 使用scroll分页的方式查询,只返回查询结果,ElasticsearchTypes.COUNT和ElasticsearchTypes.PAGINATION无效
255 | * https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-request-scroll.html
256 | * @param index 索引
257 | * @param types 类型
258 | * @param params 查询参数
259 | * @param keepAlive 快照时间
260 | * @param scrollId 上次分页标识id,初始查询时为null
261 | * @param size 每个分片返回查询的数量,最终返回的数量是:[0~分片数*size]
262 | * @return Map
263 | */
264 | public static Map selectList(String[] index, String[] types, List params, TimeValue keepAlive,String scrollId,int size){
265 | return handleSearchResponse(selectListResponse(index,types,params,keepAlive,scrollId,size));
266 | }
267 | /**
268 | * 使用scroll分页的方式查询,ElasticsearchTypes.COUNT和ElasticsearchTypes.PAGINATION无效
269 | * https://www.elastic.co/guide/en/elasticsearch/reference/2.4/search-request-scroll.html
270 | * @param index 索引
271 | * @param types 类型
272 | * @param params 查询参数
273 | * @param keepAlive 快照时间
274 | * @param scrollId 上次分页标识id,初始查询时为null
275 | * @param size 每个分片返回查询的数量,最终返回的数量是:[0~分片数*size]
276 | * @return
277 | */
278 | public static SearchResponse selectListResponse(String[] index, String[] types, List params, TimeValue keepAlive,String scrollId,int size){
279 | if(keepAlive==null){
280 | throw new RuntimeException("keepAlive 不能为空");
281 | }
282 | if(size<=0)throw new RuntimeException("size必须是一个正整数");
283 | Client client = getClient().getClient();
284 | if(StringUtils.isBlank(scrollId)){
285 | SearchRequestBuilder builder = client.prepareSearch(index).setTypes(types).setScroll(keepAlive).setSearchType(SearchType.DFS_QUERY_AND_FETCH);
286 | builder.setVersion(true);
287 | buildQueryFiled(builder,params);
288 | builder.setSize(size);
289 | SearchResponse response = builder.execute().actionGet();
290 | return response;
291 | }else{
292 | SearchResponse resultResponse = client.prepareSearchScroll(scrollId).setScroll(keepAlive).execute().actionGet();
293 | return resultResponse;
294 | }
295 | }
296 |
297 | public static Map handleSearchResponse(SearchResponse response){
298 | SearchHits hits = response.getHits();
299 | Iterator i = hits.iterator();
300 | Map result = new HashMap();
301 | List