Search in sources :

Example 16 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class ApplicationRegisterEsDAO method save.

@Override
public void save(Application application) {
    logger.debug("save application register info, application getApplicationId: {}, application code: {}", application.getId(), application.getApplicationCode());
    ElasticSearchClient client = getClient();
    Map<String, Object> source = new HashMap<>();
    source.put(ApplicationTable.COLUMN_APPLICATION_CODE, application.getApplicationCode());
    source.put(ApplicationTable.COLUMN_APPLICATION_ID, application.getApplicationId());
    source.put(ApplicationTable.COLUMN_ADDRESS_ID, application.getAddressId());
    source.put(ApplicationTable.COLUMN_IS_ADDRESS, application.getIsAddress());
    IndexResponse response = client.prepareIndex(ApplicationTable.TABLE, application.getId()).setSource(source).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    logger.debug("save application register info, application getApplicationId: {}, application code: {}, status: {}", application.getApplicationId(), application.getApplicationCode(), response.status().name());
}
Also used : HashMap(java.util.HashMap) IndexResponse(org.elasticsearch.action.index.IndexResponse) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)

Example 17 with ElasticSearchClient

use of org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient in project incubator-skywalking by apache.

the class EsDAO method getMinId.

protected final int getMinId(String indexName, String columnName) {
    ElasticSearchClient client = getClient();
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(indexName);
    searchRequestBuilder.setTypes("type");
    searchRequestBuilder.setSize(0);
    MinAggregationBuilder aggregation = AggregationBuilders.min("agg").field(columnName);
    searchRequestBuilder.addAggregation(aggregation);
    SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
    Min agg = searchResponse.getAggregations().get("agg");
    int id = (int) agg.getValue();
    if (id == Integer.MAX_VALUE || id == Integer.MIN_VALUE) {
        return 0;
    } else {
        return id;
    }
}
Also used : Min(org.elasticsearch.search.aggregations.metrics.min.Min) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) ElasticSearchClient(org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient) MinAggregationBuilder(org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

ElasticSearchClient (org.apache.skywalking.apm.collector.client.elasticsearch.ElasticSearchClient)17 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)7 SearchResponse (org.elasticsearch.action.search.SearchResponse)7 HashMap (java.util.HashMap)5 SearchHit (org.elasticsearch.search.SearchHit)5 IndexResponse (org.elasticsearch.action.index.IndexResponse)4 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)4 GetRequestBuilder (org.elasticsearch.action.get.GetRequestBuilder)3 GetResponse (org.elasticsearch.action.get.GetResponse)3 IOException (java.io.IOException)1 BatchEsDAO (org.apache.skywalking.apm.collector.storage.es.base.dao.BatchEsDAO)1 Application (org.apache.skywalking.apm.collector.storage.table.register.Application)1 NetworkAddress (org.apache.skywalking.apm.collector.storage.table.register.NetworkAddress)1 Settings (org.elasticsearch.common.settings.Settings)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)1 Max (org.elasticsearch.search.aggregations.metrics.max.Max)1 MaxAggregationBuilder (org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder)1 Min (org.elasticsearch.search.aggregations.metrics.min.Min)1 MinAggregationBuilder (org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder)1