From 96b5b20398405438bcccef8aa039b020ec6a5bad Mon Sep 17 00:00:00 2001 From: peng-yongsheng <8082209@qq.com> Date: Wed, 28 Feb 2018 22:23:19 +0800 Subject: [PATCH] searchService: add the src span type condition by the value of SpanType.Entry_VALUE. --- .../storage/es/dao/ui/ServiceNameServiceEsUIDAO.java | 7 ++++++- .../storage/h2/dao/ui/ServiceNameServiceH2UIDAO.java | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceNameServiceEsUIDAO.java b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceNameServiceEsUIDAO.java index 3775bf2816..341c2ea4b1 100644 --- a/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceNameServiceEsUIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-es-provider/src/main/java/org/apache/skywalking/apm/collector/storage/es/dao/ui/ServiceNameServiceEsUIDAO.java @@ -29,6 +29,7 @@ import org.apache.skywalking.apm.network.proto.SpanType; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; @@ -58,7 +59,11 @@ public class ServiceNameServiceEsUIDAO extends EsDAO implements IServiceNameServ searchRequestBuilder.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); searchRequestBuilder.setSize(topN); - searchRequestBuilder.setQuery(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_SERVICE_NAME, keyword)); + BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); + boolQuery.must().add(QueryBuilders.matchQuery(ServiceNameTable.COLUMN_SERVICE_NAME, keyword)); + boolQuery.must().add(QueryBuilders.termQuery(ServiceNameTable.COLUMN_SRC_SPAN_TYPE, SpanType.Entry_VALUE)); + + searchRequestBuilder.setQuery(boolQuery); SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(); SearchHit[] searchHits = searchResponse.getHits().getHits(); diff --git a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceNameServiceH2UIDAO.java b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceNameServiceH2UIDAO.java index 55c520b721..7bc2471dca 100644 --- a/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceNameServiceH2UIDAO.java +++ b/apm-collector/apm-collector-storage/collector-storage-h2-provider/src/main/java/org/apache/skywalking/apm/collector/storage/h2/dao/ui/ServiceNameServiceH2UIDAO.java @@ -60,9 +60,9 @@ public class ServiceNameServiceH2UIDAO extends H2DAO implements IServiceNameServ } @Override public List searchService(String keyword, int topN) { - String dynamicSql = "select {0},{1} from {2} where {3} like ? limit ?"; - String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_NAME); - Object[] params = new Object[] {keyword, topN}; + String dynamicSql = "select {0},{1} from {2} where {3} like ? and {4} = ? limit ?"; + String sql = SqlBuilder.buildSql(dynamicSql, ServiceNameTable.COLUMN_SERVICE_ID, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.TABLE, ServiceNameTable.COLUMN_SERVICE_NAME, ServiceNameTable.COLUMN_SRC_SPAN_TYPE); + Object[] params = new Object[] {keyword, SpanType.Entry_VALUE, topN}; List serviceInfos = new LinkedList<>(); try (ResultSet rs = getClient().executeQuery(sql, params)) { -- GitLab