@Override
  public String scan(SearchQuery searchQuery, long scrollTimeInMillis, boolean noFields) {
    Assert.notNull(searchQuery.getIndices(), "No index defined for Query");
    Assert.notNull(searchQuery.getTypes(), "No type define for Query");
    Assert.notNull(searchQuery.getPageable(), "Query.pageable is required for scan & scroll");

    SearchRequestBuilder requestBuilder =
        client
            .prepareSearch(toArray(searchQuery.getIndices()))
            .setSearchType(SCAN)
            .setQuery(searchQuery.getQuery())
            .setTypes(toArray(searchQuery.getTypes()))
            .setScroll(TimeValue.timeValueMillis(scrollTimeInMillis))
            .setFrom(0)
            .setSize(searchQuery.getPageable().getPageSize());

    if (searchQuery.getFilter() != null) {
      requestBuilder.setPostFilter(searchQuery.getFilter());
    }

    if (isNotEmpty(searchQuery.getFields())) {
      requestBuilder.addFields(toArray(searchQuery.getFields()));
    }

    if (noFields) {
      requestBuilder.setNoFields();
    }
    return requestBuilder.execute().actionGet().getScrollId();
  }
  @Override
  public <T> long count(SearchQuery searchQuery, Class<T> clazz) {
    String indexName[] =
        isNotEmpty(searchQuery.getIndices())
            ? searchQuery.getIndices().toArray(new String[searchQuery.getIndices().size()])
            : retrieveIndexNameFromPersistentEntity(clazz);
    String types[] =
        isNotEmpty(searchQuery.getTypes())
            ? searchQuery.getTypes().toArray(new String[searchQuery.getTypes().size()])
            : retrieveTypeFromPersistentEntity(clazz);

    Assert.notNull(indexName, "No index defined for Query");

    CountRequestBuilder countRequestBuilder = client.prepareCount(indexName);

    if (types != null) {
      countRequestBuilder.setTypes(types);
    }
    if (searchQuery.getQuery() != null) {
      countRequestBuilder.setQuery(searchQuery.getQuery());
    }
    return countRequestBuilder.execute().actionGet().getCount();
  }