use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project incubator-skywalking by apache.
the class NetworkAddressEsCacheDAO method getAddressId.
@Override
public int getAddressId(String networkAddress) {
ElasticSearchClient client = getClient();
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(NetworkAddressTable.TABLE);
searchRequestBuilder.setTypes(NetworkAddressTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.termQuery(NetworkAddressTable.COLUMN_NETWORK_ADDRESS, networkAddress));
searchRequestBuilder.setSize(1);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
if (searchResponse.getHits().totalHits > 0) {
SearchHit searchHit = searchResponse.getHits().iterator().next();
return ((Number) searchHit.getSource().get(NetworkAddressTable.COLUMN_ADDRESS_ID)).intValue();
}
return Const.NONE;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project incubator-skywalking by apache.
the class ApplicationAlarmEsUIDAO method loadAlarmList.
@Override
public Alarm loadAlarmList(String keyword, long startTimeBucket, long endTimeBucket, int limit, int from) throws ParseException {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(ApplicationAlarmTable.TABLE);
searchRequestBuilder.setTypes(ApplicationAlarmTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must().add(QueryBuilders.rangeQuery(ApplicationAlarmTable.COLUMN_LAST_TIME_BUCKET).gte(startTimeBucket).lte(endTimeBucket));
if (StringUtils.isNotEmpty(keyword)) {
boolQueryBuilder.must().add(QueryBuilders.matchQuery(ApplicationAlarmTable.COLUMN_ALARM_CONTENT, keyword));
}
searchRequestBuilder.setQuery(boolQueryBuilder);
searchRequestBuilder.setSize(limit);
searchRequestBuilder.setFrom(from);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
SearchHit[] searchHits = searchResponse.getHits().getHits();
Alarm alarm = new Alarm();
alarm.setTotal((int) searchResponse.getHits().getTotalHits());
for (SearchHit searchHit : searchHits) {
AlarmItem alarmItem = new AlarmItem();
alarmItem.setId(((Number) searchHit.getSource().get(ApplicationAlarmTable.COLUMN_APPLICATION_ID)).intValue());
alarmItem.setContent((String) searchHit.getSource().get(ApplicationAlarmTable.COLUMN_ALARM_CONTENT));
long lastTimeBucket = ((Number) searchHit.getSource().get(ApplicationAlarmTable.COLUMN_LAST_TIME_BUCKET)).longValue();
alarmItem.setStartTime(TimeBucketUtils.INSTANCE.formatMinuteTimeBucket(lastTimeBucket));
alarmItem.setAlarmType(AlarmType.APPLICATION);
int alarmType = ((Number) searchHit.getSource().get(ApplicationAlarmTable.COLUMN_ALARM_TYPE)).intValue();
if (org.apache.skywalking.apm.collector.storage.table.alarm.AlarmType.SLOW_RTT.getValue() == alarmType) {
alarmItem.setCauseType(CauseType.SLOW_RESPONSE);
} else if (org.apache.skywalking.apm.collector.storage.table.alarm.AlarmType.ERROR_RATE.getValue() == alarmType) {
alarmItem.setCauseType(CauseType.LOW_SUCCESS_RATE);
}
alarm.getItems().add(alarmItem);
}
return alarm;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project incubator-skywalking by apache.
the class GlobalTraceEsUIDAO method getGlobalTraceId.
@Override
public List<String> getGlobalTraceId(String segmentId) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(GlobalTraceTable.TABLE);
searchRequestBuilder.setTypes(GlobalTraceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setQuery(QueryBuilders.termQuery(GlobalTraceTable.COLUMN_SEGMENT_ID, segmentId));
searchRequestBuilder.setSize(10);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
List<String> globalTraceIds = new ArrayList<>();
SearchHit[] searchHits = searchResponse.getHits().getHits();
for (SearchHit searchHit : searchHits) {
String globalTraceId = (String) searchHit.getSource().get(GlobalTraceTable.COLUMN_GLOBAL_TRACE_ID);
logger.debug("segmentId: {}, global trace id: {}", segmentId, globalTraceId);
globalTraceIds.add(globalTraceId);
}
return globalTraceIds;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project incubator-skywalking by apache.
the class InstanceEsUIDAO method getAllServer.
@Override
public List<AppServerInfo> getAllServer(int applicationId, long startSecondTimeBucket, long endSecondTimeBucket) {
logger.debug("get instances info, applicationId: {}, start: {}, end: {}", applicationId, startSecondTimeBucket, endSecondTimeBucket);
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setSize(1000);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
boolQuery.must().add(QueryBuilders.termQuery(InstanceTable.COLUMN_IS_ADDRESS, BooleanUtils.FALSE));
BoolQueryBuilder boolQuery1 = QueryBuilders.boolQuery();
boolQuery1.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(endSecondTimeBucket));
boolQuery1.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_REGISTER_TIME).lte(endSecondTimeBucket));
BoolQueryBuilder boolQuery2 = QueryBuilders.boolQuery();
boolQuery2.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_REGISTER_TIME).lte(endSecondTimeBucket));
boolQuery2.must().add(QueryBuilders.rangeQuery(InstanceTable.COLUMN_HEARTBEAT_TIME).gte(startSecondTimeBucket));
BoolQueryBuilder timeBoolQuery = QueryBuilders.boolQuery();
timeBoolQuery.should().add(boolQuery1);
timeBoolQuery.should().add(boolQuery2);
boolQuery.must().add(timeBoolQuery);
searchRequestBuilder.setQuery(boolQuery);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
SearchHit[] searchHits = searchResponse.getHits().getHits();
return buildAppServerInfo(searchHits);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.SearchHit in project incubator-skywalking by apache.
the class InstanceEsUIDAO method getEarliestRegisterTime.
@Override
public long getEarliestRegisterTime(int applicationId) {
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(InstanceTable.TABLE);
searchRequestBuilder.setTypes(InstanceTable.TABLE_TYPE);
searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH);
searchRequestBuilder.setSize(1);
searchRequestBuilder.setQuery(QueryBuilders.termQuery(InstanceTable.COLUMN_APPLICATION_ID, applicationId));
searchRequestBuilder.addSort(SortBuilders.fieldSort(InstanceTable.COLUMN_REGISTER_TIME).sortMode(SortMode.MIN));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
SearchHit[] searchHits = searchResponse.getHits().getHits();
if (searchHits.length > 0) {
return ((Number) searchHits[0].getSource().get(InstanceTable.COLUMN_REGISTER_TIME)).longValue();
}
return Long.MIN_VALUE;
}
Aggregations