Use ids query method instead of get method for metrics persistence. (#2934)
* Use ids query method instead of get method for metrics persistence. #2933 * Query by alias name.
This commit is contained in:
parent
d844a52587
commit
129d2918ac
|
|
@ -218,6 +218,15 @@ public class ElasticSearchClient implements Client {
|
|||
return client.get(request);
|
||||
}
|
||||
|
||||
public SearchResponse idQuery(String indexName, String id) throws IOException {
|
||||
indexName = formatIndexName(indexName);
|
||||
|
||||
SearchRequest searchRequest = new SearchRequest(indexName);
|
||||
searchRequest.types(TYPE);
|
||||
searchRequest.source().query(QueryBuilders.idsQuery().addIds(id));
|
||||
return client.search(searchRequest);
|
||||
}
|
||||
|
||||
public Map<String, Map<String, Object>> ids(String indexName, String... ids) throws IOException {
|
||||
indexName = formatIndexName(indexName);
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,8 @@ import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
|
|||
import org.apache.skywalking.oap.server.core.storage.*;
|
||||
import org.apache.skywalking.oap.server.core.storage.model.Model;
|
||||
import org.apache.skywalking.oap.server.library.client.elasticsearch.ElasticSearchClient;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
|
||||
|
|
@ -41,10 +41,9 @@ public class MetricsEsDAO extends EsDAO implements IMetricsDAO<IndexRequest, Upd
|
|||
}
|
||||
|
||||
@Override public Metrics get(Model model, Metrics metrics) throws IOException {
|
||||
String modelName = TimeSeriesUtils.timeSeries(model, metrics.getTimeBucket());
|
||||
GetResponse response = getClient().get(modelName, metrics.id());
|
||||
if (response.isExists()) {
|
||||
return storageBuilder.map2Data(response.getSource());
|
||||
SearchResponse response = getClient().idQuery(model.getName(), metrics.id());
|
||||
if (response.getHits().totalHits > 0) {
|
||||
return storageBuilder.map2Data(response.getHits().getAt(0).getSourceAsMap());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue