[ https://issues.apache.org/jira/browse/METRON-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16112811#comment-16112811 ]
ASF GitHub Bot commented on METRON-1075: ---------------------------------------- Github user ottobackwards commented on a diff in the pull request: https://github.com/apache/metron/pull/679#discussion_r131156937 --- Diff: metron-platform/metron-elasticsearch/src/main/java/org/apache/metron/elasticsearch/dao/ElasticsearchDao.java --- @@ -179,4 +206,43 @@ public void init(Map<String, Object> globalConfig, AccessConfig config) { return latestIndices.values().toArray(new String[latestIndices.size()]); } + public void addFacetFields(SearchSourceBuilder searchSourceBuilder, List<String> fields) { + for(String field: fields) { + searchSourceBuilder = searchSourceBuilder.aggregation(new TermsBuilder(getAggregationName(field)).field(field)); + } + } + + public Map<String, Map<String, Long>> getFacetCounts(List<String> fields, Aggregations aggregations, Map<String, FieldType> commonColumnMetadata) { + Map<String, Map<String, Long>> fieldCounts = new HashMap<>(); + for (String field: fields) { + Map<String, Long> valueCounts = new HashMap<>(); + Aggregation aggregation = aggregations.get(getAggregationName(field)); + if (aggregation instanceof LongTerms) { + LongTerms longTerms = (LongTerms) aggregation; + FieldType type = commonColumnMetadata.get(field); + if (FieldType.IP.equals(type)) { + longTerms.getBuckets().stream().forEach(bucket -> valueCounts.put(IpFieldMapper.longToIp((Long) bucket.getKey()), bucket.getDocCount())); + } else if (FieldType.BOOLEAN.equals(type)) { + longTerms.getBuckets().stream().forEach(bucket -> { + String key = (Long) bucket.getKey() == 1 ? "true" : "false"; + valueCounts.put(key, bucket.getDocCount()); + }); + } else { + longTerms.getBuckets().stream().forEach(bucket -> valueCounts.put(bucket.getKeyAsString(), bucket.getDocCount())); + } + } else if (aggregation instanceof DoubleTerms) { + DoubleTerms doubleTerms = (DoubleTerms) aggregation; + doubleTerms.getBuckets().stream().forEach(bucket -> valueCounts.put(bucket.getKeyAsString(), bucket.getDocCount())); + } else if (aggregation instanceof StringTerms) { + StringTerms stringTerms = (StringTerms) aggregation; + stringTerms.getBuckets().stream().forEach(bucket -> valueCounts.put(bucket.getKeyAsString(), bucket.getDocCount())); + } + fieldCounts.put(field, valueCounts); --- End diff -- Thanks! > Add faceted search capabilities > ------------------------------- > > Key: METRON-1075 > URL: https://issues.apache.org/jira/browse/METRON-1075 > Project: Metron > Issue Type: New Feature > Reporter: Ryan Merriman > Assignee: Ryan Merriman > > We need a way to perform faceted searches against our search engine. A > faceted search returns a distribution of values across search results for a > given set of facet fields. This should be part of our DAO indexing > abstraction. -- This message was sent by Atlassian JIRA (v6.4.14#64029)