You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metron.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/08/17 16:47:00 UTC

[jira] [Commented] (METRON-1114) Add group by capabilities to search REST endpoint

    [ https://issues.apache.org/jira/browse/METRON-1114?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16130799#comment-16130799 ] 

ASF GitHub Bot commented on METRON-1114:
----------------------------------------

GitHub user merrimanr opened a pull request:

    https://github.com/apache/metron/pull/702

    METRON-1114: Add group by capabilities to search REST endpoint

    ## Contributor Comments
    This PR adds a group by feature to the search REST endpoint.  This PR is fairly complex so I don't think it should be merged before a thorough discussion and review.
    
    The following is an intentionally simple example of how group by works.  Normally a search query would be issued and the results returned would be similar to:
    ```
    {
      "total": 100,
      "results": [
        { ... },
        { ... },
        and so on
      ]
    }
    ```
    
    This PR allows a user to group results based on a field or list of fields.  For example, grouping results by a field called "fieldA" would be done by including a "groupByFields" property:
    ```
    {
      "groupByFields":["fieldA"],
      "from": 0,
      "query": "*",
      ...
    }
    ```
    The results would then change to this form:
    ```
    {
      "total": 100,
      "groupedBy": "fieldA",
      "groups": [
        {
          "key": "value1",
          "results": [
            { ... },
            { ... },
            and so on
          ]
      ]
    }
    ```
    Grouping by multiple fields would just be a matter of adding a field to the "groupByFields" list:
    ```
    {
      "groupByFields":["fieldA", "fieldB"],
      "from": 0,
      "query": "*",
      ...
    }
    ```
    The groups would then be nested based on the order they appear in the list:
    ```
    {
      "total": 100,
      "groupedBy": "fieldA",
      "groups": [
        {
          "key": "fieldA value1",
          "groupedBy": "fieldB",
          "groups": [
            {
              "key": "fieldB value1",
              "results": [
                { ... },
                { ... },
                and so on
              ]
            },
            {
             "key": "fieldB value2",
             "results": [
                { ... },
                { ... },
                and so on
              ]
            }
          ]
        } 
      ]
    }
    ```
    This has been verified and tested in full dev.  For example, this search query:
    ```
    {
      "groupByFields":["ip_src_addr","ip_dst_port"],
      "from": 0,
      "indices": [
        "bro"
      ],
      "query": "*",
      "size": 5
    }
    ```
    should return search results properly grouped by those fields.  The "size" and "sort" parameters also apply to groups of search results, however the "from" parameter does not because it doesn't make sense for that type of query (and ES doesn't support it from what I can tell).
    
    There are a couple of outstanding issues that we need to work through before this gets merged:  
    
    - The group by feature is included as part of the general search feature but having worked through the implementation, I'm not sure this is still the best approach.  There is non-trivial conditional logic that I think makes this class harder to understand and it might make sense to move this group by query to a separate endpoint.  Interested to hear others' perspective on this since I am so close to it.  
    
    - I also did a fair amount of refactoring in an attempt to make this class easier to read.  If that is not the case and the refactoring made it worse, let me know.  
    
    - And finally (it has been requested in the past), I think we definitely need more detailed documentation around this particular endpoint.  I am planning on adding some extensive documentation to this PR once we settle on an API design approach.  The alerts UI isn't quite ready for this feature so there's no rush in getting this merged.
    
    ## Pull Request Checklist
    
    Thank you for submitting a contribution to Apache Metron.  
    Please refer to our [Development Guidelines](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61332235) for the complete guide to follow for contributions.  
    Please refer also to our [Build Verification Guidelines](https://cwiki.apache.org/confluence/display/METRON/Verifying+Builds?show-miniview) 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:
    - [x] Is there a JIRA ticket associated with this PR? If not one needs to be created at [Metron Jira](https://issues.apache.org/jira/browse/METRON/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel). 
    - [x] 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.
    - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    
    ### For code changes:
    - [x] Have you included steps to reproduce the behavior or problem that is being changed or addressed?
    - [x] Have you included steps or a guide to how the change may be verified and tested manually?
    - [x] 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 
      ```
    
    - [x] Have you written or updated unit tests and or integration tests to verify your changes?
    - [x] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
    - [x] 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:
    - [x] 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](https://travis-ci.org) is set up for your personal repository such that your branches are built there before submitting a pull request.
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/merrimanr/incubator-metron METRON-1114

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/metron/pull/702.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #702
    
----
commit 3650ef9aeea49d8238bf2e409ec0885120722b59
Author: merrimanr <me...@gmail.com>
Date:   2017-08-17T14:36:05Z

    initial commit

commit a4f0ba9008f2d0ee48b8bcd639558ac955249490
Author: merrimanr <me...@gmail.com>
Date:   2017-08-17T14:40:51Z

    moved group by test cases to the end

----


> Add group by capabilities to search REST endpoint
> -------------------------------------------------
>
>                 Key: METRON-1114
>                 URL: https://issues.apache.org/jira/browse/METRON-1114
>             Project: Metron
>          Issue Type: New Feature
>            Reporter: Ryan Merriman
>            Assignee: Ryan Merriman
>
> We need a way to group search results.  Instead of all search results being included in a single list, they would instead be grouped together based a list of fields.  For example, if "ip_src_addr" was set to the groupBy field, all results with the same value for that field would be in a group together.  All other search features would still apply to the groups including filtering, sorting and result set size. 



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)