Github user ottobackwards commented on a diff in the pull request:

    https://github.com/apache/metron/pull/679#discussion_r131128135
  
    --- 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 --
    
    Are there any other *Terms here or does this cover our "Other" type?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to