Search in sources :

Example 96 with SearchHit

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;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 97 with SearchHit

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;
}
Also used : AlarmItem(org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmItem) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) Alarm(org.apache.skywalking.apm.collector.storage.ui.alarm.Alarm) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 98 with SearchHit

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;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) ArrayList(java.util.ArrayList) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 99 with SearchHit

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);
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 100 with SearchHit

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;
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchHit(org.elasticsearch.search.SearchHit) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

SearchHit (org.elasticsearch.search.SearchHit)318 SearchResponse (org.elasticsearch.action.search.SearchResponse)225 SearchHits (org.elasticsearch.search.SearchHits)87 ArrayList (java.util.ArrayList)83 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)64 HashMap (java.util.HashMap)37 Map (java.util.Map)37 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)37 IOException (java.io.IOException)35 Test (org.junit.Test)32 TimeValue (org.elasticsearch.common.unit.TimeValue)29 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)25 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)23 SearchRequest (org.elasticsearch.action.search.SearchRequest)22 List (java.util.List)17 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)17 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)17 SearchHitField (org.elasticsearch.search.SearchHitField)16 HashSet (java.util.HashSet)15 Text (org.elasticsearch.common.text.Text)14