检索索引所有数据
@param index
@param fetchSize 指定每批次返回的数据，不指定默认为5000
@param scrollHandler 每批数据处理方法
@param type
@param <T>
@return
@throws ElasticSearchException
19169
public <T> ESDatas<T> searchAll(String index,  int fetchSize ,ScrollHandler<T> scrollHandler,Class<T> type) throws ElasticSearchException{
		StringBuilder builder = new StringBuilder();
		String queryAll = builder.append("{ \"size\":").append(fetchSize).append(",\"query\": {\"match_all\": {}},\"sort\": [\"_doc\"]}").toString();
		builder.setLength(0);
		return this.scroll(builder.append(index).append("/_search").toString(),queryAll,"10m",type,scrollHandler);
	}
1117687
public SearchResponse searchAllWithTargetCount(String index, String type,
            AggregationBuilder[] aggregationBuilders) {
        return searchAllWithTargetCount(index, type, null, aggregationBuilders);
    }
385875
public <T> ESDatas<T> searchAllParallel(String index,  final int fetchSize ,ScrollHandler<T> scrollHandler,final Class<T> type,int max) throws ElasticSearchException{
		if(!this.client.isV1()) {
			SliceScroll sliceScroll = new SliceScroll() {
				@Override
				public String buildSliceDsl(int sliceId, int max) {
					StringBuilder builder = new StringBuilder();
					String sliceDsl = builder.append("{\"slice\": {\"id\": ").append(sliceId).append(",\"max\": ")
							.append(max).append("},\"size\":").append(fetchSize).append(",\"query\": {\"match_all\": {}},\"sort\": [\"_doc\"]}").toString();
					return sliceDsl;
//				return buildSliceDsl(i,max, params, dslTemplate);
				}
			};

			return _slice(index + "/_search", scrollHandler, type, max, "1m", sliceScroll);
		}
		else{
			StringBuilder builder = new StringBuilder();
			String queryAll = builder.append("{ \"size\":").append(fetchSize).append(",\"query\": {\"match_all\": {}},\"sort\": [\"_doc\"]}").toString();
			builder.setLength(0);
			return this.scrollParallel(builder.append(index).append("/_search").toString(),queryAll,"10m",type,scrollHandler);
		}

	}
296380
public <T> ESDatas<T> searchAllParallel(String index,  int fetchSize ,Class<T> type,int thread) throws ElasticSearchException{
		return searchAllParallel(index,  fetchSize,(ScrollHandler<T>)null,type,thread);
	}
757870
protected <T> ESDatas<T> _slice(String path,  ScrollHandler<T> scrollHandler,final Class<T> type,int max,
								  final String scroll,SliceScroll sliceScroll) throws ElasticSearchException{



		long starttime = System.currentTimeMillis();
		//scroll slice分页检索

//		final CountDownLatch countDownLatch = new CountDownLatch(max);//线程任务完成计数器，每个线程对应一个sclice,每运行完一个slice任务,countDownLatch计数减去1

		final String _path = path.indexOf('?') < 0 ? new StringBuilder().append(path).append("?scroll=").append(scroll).toString() :
				new StringBuilder().append(path).append("&scroll=").append(scroll).toString();

		ExecutorService executorService = this.client.getSliceScrollQueryExecutorService();
		List<Future> tasks = new ArrayList<Future>();
		//辅助方法，用来累计每次scroll获取到的记录数
		final ParallelSliceScrollResult sliceScrollResult = new ParallelSliceScrollResult();
		if(scrollHandler != null)
			sliceScrollResult.setScrollHandler(scrollHandler);

		try {
//			SliceRunTask<T> sliceRunTask = null;
			SerialContext serialContext = ESInnerHitSerialThreadLocal.buildSerialContext();
			for (int j = 0; j < max; j++) {//启动max个线程，并行处理每个slice任务
				String sliceDsl = sliceScroll.buildSliceDsl(j,max);
//				final String sliceDsl = builder.append("{\"slice\": {\"id\": ").append(i).append(",\"max\": ")
//									.append(max).append("},\"size\":").append(fetchSize).append(",\"query\": {\"match_all\": {}}}").toString();

				runSliceTask(j,_path,sliceDsl,scroll,type,sliceScrollResult,
						executorService,tasks,serialContext );
			}
		}
		finally {
			waitTasksComplete(tasks);
		}

		//打印处理耗时和实际检索到的数据
		if(logger.isDebugEnabled()) {
			long endtime = System.currentTimeMillis();
			logger.debug("Slice scroll query耗时：" + (endtime - starttime) + ",realTotalSize：" + sliceScrollResult.getRealTotalSize());
		}


		sliceScrollResult.complete();
		return sliceScrollResult.getSliceResponse();
	}
854684
def _fetch_elasticsearch(self, es_query):
        
        # TODO: Show error if index is not found.
        scanResp = self._esd.search(index=self.config['es_index'],
                                    body=es_query, size=2000,
                                    search_type="scan", scroll="10000",
                                    timeout=900, request_timeout=900)
        resp = dict(scanResp)
        resp.pop('_scroll_id')
        logger.debug(resp)
        scroll_hits = scanResp['hits']['total']
        scrollTime = scanResp['took']
        scrollId = scanResp['_scroll_id']
        # Check for shard errors
        if scanResp['_shards']['failed'] > 0:
            logger.warn("Failing shards, check ES")
        retry_count = 0
        number_of_retrys = 5
        hit_count = 0

        while True:
            try:
                response = self._esd.scroll(scroll_id=scrollId, scroll="10000",
                                            request_timeout=900)
                if response['_scroll_id'] != scrollId:
                    scrollId = response['_scroll_id']
                if scanResp['_shards']['failed'] > 0:
                    print("Failing shards, check ES")
                # No more hits
                if len(response["hits"]["hits"]) == 0:
                    break
            except esd_exceptions.ConnectionTimeout:
                logger.warning("ES exceptions: Connection Timeout")
                if retry_count >= number_of_retrys:
                    raise esd_exceptions.ConnectionTimeout()

                retry_count += 1
                continue

            except StopIteration:
                break

            except Exception as e:
                # TODO: Logging
                logging.exception("ES exception", exc_info=True)
                print("EXCEPTION")
                print(e)
                break

            for hit in response["hits"]["hits"]:
                yield hit
                hit_count += 1

        if hit_count > scroll_hits:
            # More hits as expected, happens sometimes.
            logger.info('More hits as expected %s/%s', hit_count, scroll_hits)
        elif hit_count < scroll_hits:
            # Less hits as expected, something went wrong.
            logger.warn('Less hits as expected %s/%s', hit_count, scroll_hits)
        logger.info('%s Hits', hit_count)
1274709
public <T> T getDocument(String indexName, String indexType,String documentId,Class<T> beanType) throws ElasticSearchException{
		return getDocument(  indexName,   indexType,  documentId,(Map<String,Object>)null,beanType);
	}
653756
private void checkTexRange(AiTextureType type, int index) {
        if (index < 0 || index > m_numTextures.get(type)) {
            throw new IndexOutOfBoundsException("Index: " + index + ", Size: " +
                    m_numTextures.get(type));
        }
    }
218443
public <T> T getDocument(String indexName, String indexType,String documentId,Map<String,Object> options,Class<T> beanType) throws ElasticSearchException{
		try{
			SearchHit searchResult = this.client.executeRequest(BuildTool.buildGetDocumentRequest(  indexName,   indexType,  documentId,  options),null,   new GetDocumentResponseHandler( beanType),ClientUtil.HTTP_GET);

			return ResultUtil.buildObject(searchResult, beanType);
		}
		catch(ElasticSearchException e){
			return ResultUtil.hand404HttpRuntimeException(e,beanType,ResultUtil.OPERTYPE_getDocument);
		}

	}
783980
public void deleteByQuery(String index, String type) throws IOException {
        logger.debug("deleteByQuery [{}]/[{}]", index, type);

        String deleteByQuery = "{\n" +
                "  \"query\": {\n" +
                "    \"match_all\": {}\n" +
                "  }\n" +
                "}";

        Request request = new Request("POST", "/" + index + "/" + type + "/_delete_by_query");
        request.setJsonEntity(deleteByQuery);
        Response restResponse = client.getLowLevelClient().performRequest(request);
        Map<String, Object> response = asMap(restResponse);
        logger.debug("reindex response: {}", response);
    }
901946
public  <T> ESDatas<T> scroll(String path,String dslTemplate,String scroll,Map params,Class<T> type) throws ElasticSearchException{
		throw new java.lang.UnsupportedOperationException();
	}
110979
public long count(String[] indices, String[] types,
            QueryBuilder filterQueryBuilder) {
        return countQuery(getSearchRequestBuilderWithMatchAll(false, indices,
                types, filterQueryBuilder));
    }
916539
public void sendBulkDataWithObjectMapperAsync(List<Object> objectBulkData,
            String index, String type) {
        executeBulkRequestAsync(buildBulkIndexRequestBuilder(objectBulkData
                .stream()
                .map(sourceObject -> jmESClient.prepareIndex(index, type)
                        .setSource(JMElasticsearchUtil
                                .buildSourceByJsonMapper(sourceObject)))
                .collect(toList())));
    }
743838
public <T> SQLResult<T>  fetchQuery(Class<T> beanType,  String templateName) throws ElasticSearchException {
		SQLRestResponse result = this.client.executeRequest("/_xpack/sql",ESTemplateHelper.evalTemplate(esUtil,templateName, (Map)null),   new SQLRestResponseHandler());
		SQLResult<T> datas = ResultUtil.buildFetchSQLResult(  result,  beanType,  (SQLResult<T> )null);
		datas.setClientInterface(this);
		return datas;
	}
1022309
public T get(int index) {
		if (index >= items.size() || index < 0) {
			throw new IndexOutOfBoundsException("size: " + items.size() + " index: " + index);
		}
		return items.get(index);
	}
983277
public <H extends EventHandler> H getHandler(GwtEvent.Type<H> type, int index) {
		return this.eventBus.superGetHandler(type, index);
	}
438489
@Override
  public IndexRequestBuilder createIndexRequest(Client client,
        String indexPrefix, String indexType, Event event) throws IOException {
    IndexRequestBuilder request = prepareIndex(client);
    String realIndexPrefix = BucketPath.escapeString(indexPrefix, event.getHeaders());
    String realIndexType = BucketPath.escapeString(indexType, event.getHeaders());

    TimestampedEvent timestampedEvent = new TimestampedEvent(event);
    long timestamp = timestampedEvent.getTimestamp();

    String indexName = getIndexName(realIndexPrefix, timestamp);
    prepareIndexRequest(request, indexName, realIndexType, timestampedEvent);
    return request;
  }