def test_date_histogram_interval_types(interval_type, interval): dhf = DateHistogramFacet(field="@timestamp", **{interval_type: interval}) assert dhf.get_aggregation().to_dict() == { "date_histogram": { "field": "@timestamp", interval_type: interval, "min_doc_count": 0, } } dhf.get_value_filter(datetime.now())
class RepoSearch(FacetedSearch): doc_types = [Repos] facets = { 'public': TermsFacet(field='is_public'), 'created': DateHistogramFacet(field='created_at', interval='month') }
class PRSearch(FacetedSearch): index = 'test-prs' doc_types = [PullRequest] facets = { 'comments': NestedFacet( 'comments', DateHistogramFacet(field='comments.created_at', interval='month')) }
class CommitSearch(FacetedSearch): doc_types = ['commits'] fields = ('description', 'files', ) facets = { 'files': TermsFacet(field='files'), 'frequency': DateHistogramFacet(field='authored_date', interval="day", min_doc_count=1), 'deletions': RangeFacet(field='stats.deletions', ranges=[('ok', (None, 1)), ('good', (1, 5)), ('better', (5, None))]) }
class PRSearch(FacetedSearch): index = "test-prs" doc_types = [PullRequest] facets = { "comments": NestedFacet( "comments", DateHistogramFacet(field="comments.created_at", interval="month"), ) }
class RepoSearch(FacetedSearch): index = 'git' facets = { 'public': TermsFacet(field='is_public'), 'created': DateHistogramFacet(field='created_at', interval='month') } def search(self): s = super(RepoSearch, self).search() return s.filter('term', commit_repo='repo')
class RepoSearch(FacetedSearch): index = "git" doc_types = [Repos] facets = { "public": TermsFacet(field="is_public"), "created": DateHistogramFacet(field="created_at", interval="month"), } def search(self): s = super(RepoSearch, self).search() return s.filter("term", commit_repo="repo")
class CommitSearch(FacetedSearch): index = "flat-git" fields = ( "description", "files", ) facets = { "files": TermsFacet(field="files"), "frequency": DateHistogramFacet( field="authored_date", interval="day", min_doc_count=1 ), "deletions": RangeFacet( field="stats.deletions", ranges=[("ok", (None, 1)), ("good", (1, 5)), ("better", (5, None))], ), }
def test_date_histogram_facet_with_1970_01_01_date(): dhf = DateHistogramFacet() assert dhf.get_value({"key": None}) == datetime(1970, 1, 1, 0, 0) assert dhf.get_value({"key": 0}) == datetime(1970, 1, 1, 0, 0)
def test_date_histogram_facet_with_1970_01_01_date(): dhf = DateHistogramFacet() assert dhf.get_value({'key': None}) == datetime(1970, 1, 1, 0, 0) assert dhf.get_value({'key': 0}) == datetime(1970, 1, 1, 0, 0)
def test_date_histogram_no_interval_keyerror(): dhf = DateHistogramFacet(field="@timestamp") with pytest.raises(KeyError) as e: dhf.get_value_filter(datetime.now()) assert str(e.value) == "'interval'"