protected static List < Trace > internalQuery ( ElasticsearchClient client , String tenantId , Criteria criteria ) { List < Trace > ret = new ArrayList < Trace > ( ) ; String index = client . getIndex ( tenantId ) ; try { RefreshRequestBuilder refreshRequestBuilder = client . getClient ( ) . admin ( ) . indices ( ) . prepareRefresh ( index ) ; client . getClient ( ) . admin ( ) . indices ( ) . refresh ( refreshRequestBuilder . request ( ) ) . actionGet ( ) ; BoolQueryBuilder query = ElasticsearchUtil . buildQuery ( criteria , ElasticsearchUtil . TRANSACTION_FIELD , Trace . class ) ; SearchRequestBuilder request = client . getClient ( ) . prepareSearch ( index ) . setTypes ( TRACE_TYPE ) . setSearchType ( SearchType . DFS_QUERY_THEN_FETCH ) . setTimeout ( TimeValue . timeValueMillis ( criteria . getTimeout ( ) ) ) . setSize ( criteria . getMaxResponseSize ( ) ) . setQuery ( query ) . addSort ( ElasticsearchUtil . TIMESTAMP_FIELD , SortOrder . ASC ) ; FilterBuilder filter = ElasticsearchUtil . buildFilter ( criteria ) ; if ( filter != null ) { request . setPostFilter ( filter ) ; } SearchResponse response = request . execute ( ) . actionGet ( ) ; if ( response . isTimedOut ( ) ) { msgLog . warnQueryTimedOut ( ) ; } for ( SearchHit searchHitFields : response . getHits ( ) ) { try { ret . add ( mapper . readValue ( searchHitFields . getSourceAsString ( ) , Trace . class ) ) ; } catch ( Exception e ) { msgLog . errorFailedToParse ( e ) ; } } if ( msgLog . isTraceEnabled ( ) ) { msgLog . tracef ( "Query traces with criteria[%s] is: %s" , criteria , ret ) ; } } catch ( org . elasticsearch . indices . IndexMissingException ime ) { // Ignore, as means that no traces have // been stored yet if ( msgLog . isTraceEnabled ( ) ) { msgLog . tracef ( "No index found, so unable to retrieve traces" ) ; } } catch ( org . elasticsearch . action . search . SearchPhaseExecutionException spee ) { // Ignore, as occurs when mapping not established (i.e. empty // repository) and performing query with a sort order if ( msgLog . isTraceEnabled ( ) ) { msgLog . tracef ( "Failed to get fragments" , spee ) ; } } return ret ; }
This method performs the query .