Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

METRON-1075: Add faceted search capabilities#679

Closed
merrimanr wants to merge 1 commit intoapache:masterfrom
merrimanr:METRON-1075
Closed

METRON-1075: Add faceted search capabilities#679
merrimanr wants to merge 1 commit intoapache:masterfrom
merrimanr:METRON-1075

Conversation

@merrimanr
Copy link
Contributor

Contributor Comments

This PR adds faceted search to indexing DAO. This can be tested in full dev with Swagger. When searching with the "/api/v1/search/search" endpoint adding a "facetFields" property with a list of fields as the value will return facet counts for those fields. For example, for this request:

{
  "facetFields": [
    "ip_src_addr"
  ],
  "from": 0,
  "indices": [
    "bro", "snort"
  ],
  "query": "*",
  "size": 5
}

A "facetCounts" property will be added to the result, looking similar to:

"facetCounts": {
    "ip_src_addr": {
      "95.163.121.204": 1913,
      "72.34.49.86": 2159,
      "192.168.138.158": 45167,
      "188.165.164.184": 82,
      "192.168.138.2": 120,
      "192.168.66.1": 30771,
      "62.75.195.236": 11513,
      "192.168.66.121": 3793,
      "204.152.254.221": 767
    }
  }

If the "facetFields" property is left out, the search will function the same.

Pull Request Checklist

Thank you for submitting a contribution to Apache Metron.
Please refer to our Development Guidelines for the complete guide to follow for contributions.
Please refer also to our Build Verification Guidelines for complete smoke testing guides.

In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:

For all changes:

  • Is there a JIRA ticket associated with this PR? If not one needs to be created at Metron Jira.
  • Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
  • Has your PR been rebased against the latest commit within the target branch (typically master)?

For code changes:

  • Have you included steps to reproduce the behavior or problem that is being changed or addressed?

  • Have you included steps or a guide to how the change may be verified and tested manually?

  • Have you ensured that the full suite of tests and checks have been executed in the root metron folder via:

    mvn -q clean integration-test install && build_utils/verify_licenses.sh 
    
  • Have you written or updated unit tests and or integration tests to verify your changes?

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?

  • Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via site-book/target/site/index.html:

    cd site-book
    mvn site
    

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
It is also recommended that travis-ci is set up for your personal repository such that your branches are built there before submitting a pull request.

Copy link
Contributor

@ottobackwards ottobackwards left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, just one quick question. Running up in full dev now.

StringTerms stringTerms = (StringTerms) aggregation;
stringTerms.getBuckets().stream().forEach(bucket -> valueCounts.put(bucket.getKeyAsString(), bucket.getDocCount()));
}
fieldCounts.put(field, valueCounts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other *Terms here or does this cover our "Other" type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ES java api can be pretty awkward to use. This is a good example of that. The Aggregation object is abstract and has 3 subclasses related to term aggregations: LongTerms, DoubleTerms and StringTerms. All types fall into one of these (as far as I could tell) which is one reason we needed a function to get the fields types. For example, an aggregation for a field of type "ip" is represented as a LongTerms object and the value returned is also a long. To get it to display correct we need to convert it to a string representation of the ip address. Same thing for booleans. There are returned as LongTerms with a value of 1 or 0.

Hopefully I covered all the different types in the integration tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ottobackwards
Copy link
Contributor

+1 works as described. Great Job!

@asfgit asfgit closed this in 42fff74 Aug 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants