private FetchOptions createAppLogFetchOptions(LogQuery logQuery) {
   FetchOptions fetchOptions = new FetchOptions();
   fetchOptions.fetchMode(FetchOptions.FetchMode.LAZY);
   if (logQuery.getBatchSize() != null) {
     fetchOptions.fetchSize(logQuery.getBatchSize());
   }
   return fetchOptions;
 }
  private CacheQuery createRequestLogsQuery(CapedwarfLogQuery logQuery) {
    LogQuery query = logQuery.getQuery();
    QueryBuilder queryBuilder =
        searchManager.buildQueryBuilderForClass(CapedwarfRequestLogs.class).get();
    List<Query> queries = new ArrayList<Query>();
    if (query.getStartTimeUsec() != null) {
      queries.add(
          queryBuilder
              .range()
              .onField(CapedwarfRequestLogs.END_TIME_USEC)
              .above(query.getStartTimeUsec())
              .createQuery());
    }
    if (query.getEndTimeUsec() != null) {
      queries.add(
          queryBuilder
              .range()
              .onField(CapedwarfRequestLogs.END_TIME_USEC)
              .below(query.getEndTimeUsec())
              .createQuery());
    }
    if (query.getMinLogLevel() != null) {
      queries.add(
          queryBuilder
              .range()
              .onField(CapedwarfRequestLogs.MAX_LOG_LEVEL)
              .above(query.getMinLogLevel().ordinal())
              .createQuery());
    }

    boolean onlyCompleteRequests = !Boolean.TRUE.equals(query.getIncludeIncomplete());
    if (onlyCompleteRequests) {
      queries.add(
          queryBuilder
              .keyword()
              .onField(CapedwarfRequestLogs.FINISHED)
              .matching(Boolean.TRUE)
              .createQuery());
    }

    Query luceneQuery = getQuery(queryBuilder, queries);
    CacheQuery cacheQuery = searchManager.getQuery(luceneQuery, CapedwarfRequestLogs.class);
    cacheQuery.sort(
        new Sort(new SortField(CapedwarfRequestLogs.END_TIME_USEC, SortField.LONG, true)));
    cacheQuery.firstResult(logQuery.getOptions().getOffset());
    if (logQuery.getOptions().getLimit() != null) {
      cacheQuery.maxResults(logQuery.getOptions().getLimit());
    }
    return cacheQuery;
  }