code: public List executeQuery(QueryBuilder filter, AggregationBuilder aggregation, final EntityMetadata entityMetadata,
              KunderaQuery query, int firstResult, int maxResults)
      {
          String[] fieldsToSelect = query.getResult();
          Class clazz = entityMetadata.getEntityClazz();
  
          MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
                  .getMetamodel(entityMetadata.getPersistenceUnit());
  
          FilteredQueryBuilder queryBuilder = QueryBuilders.filteredQuery(null, filter);
          SearchRequestBuilder builder = txClient.prepareSearch(entityMetadata.getSchema().toLowerCase())
                  .setTypes(entityMetadata.getTableName());
  
          addFieldsToBuilder(fieldsToSelect, clazz, metaModel, builder);
  
          if (aggregation == null)
          {
              builder.setQuery(queryBuilder);
              builder.setFrom(firstResult);
              builder.setSize(maxResults);
              addSortOrder(builder, query, entityMetadata);
          }
          else
          {
              logger.debug("Aggregated query identified");
              builder.addAggregation(aggregation);
  
              if (fieldsToSelect.length == 1
                      || (query.isSelectStatement() && query.getSelectStatement().hasGroupByClause()))
              {
                  builder.setSize(0);
              }
          }
  
          SearchResponse response = null;
          logger.debug("Query generated: " + builder);
  
          try
          {
              response = builder.execute().actionGet();
              logger.debug("Query execution response: " + response);
          }
          catch (ElasticsearchException e)
          {
              logger.error("Exception occured while executing query on Elasticsearch.", e);
              throw new KunderaException("Exception occured while executing query on Elasticsearch.", e);
          }
  
          return esResponseReader.parseResponse(response, aggregation, fieldsToSelect, metaModel, clazz, entityMetadata,
                  query);
      }
docs: Execute query.
  
  @param filter
  the filter
  @param aggregation
  the aggregation
  @param entityMetadata
  the entity metadata
  @param query
  the query
  @param firstResult
  the first result
  @param maxResults
  the max results
  @return the list