inveniosoftware / react-searchkit

React component library for interacting with a REST API.
https://inveniosoftware.github.io/react-searchkit/
MIT License
78 stars 40 forks source link

Feature: filters #87

Open kpsherva opened 4 years ago

kpsherva commented 4 years ago

implement filters when no key in the aggregation response (has_files):

aggregations: {
    access: {
        buckets: [
           {
               doc_count: 18,
               key: 0,
               key_as_string: "false"
            },
           {
               doc_count: 12,
               key: 1,
               key_as_string: "true"
            }
         ],
        doc_count_error_upper_bound: 0,
        sum_other_doc_count: 0
    }, 
    has_files: {
        buckets: {
            has_files: {
                doc_count: 1
            },
            no_files: {
                doc_count: 29
            }
        }
    }
}

the filter defined as:

 eitems=dict(
        aggs=dict(
            access=dict(terms=dict(field="open_access")),
            has_files=dict(
                filters=dict(
                    filters=dict(
                        has_files=dict(exists=dict(field="files.file_id")),
                        no_files=dict(
                            bool=dict(
                                must_not=dict(
                                    exists=dict(field="files.file_id")
                                )
                            )
                        ),
                    )
                )
            )
        ),
        post_filters=dict(
            access=terms_filter("open_access"),
            has_files=not_empty_object_or_list_filter("files.file_id")
        )
    ),

ES documentation: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filters-aggregation.html

based on this documentation rename BucketAggregation component to BucketTermAggregation and create BucketFilterAggregation to reflect the behaviour of elasticsearch