@@ -6,8 +6,8 @@ Django app for storing time-series metrics in Elasticsearch.
66
77python importables:
88- ` elasticsearch_metrics `
9- - ` elasticsearch_metrics.imps.elastic8 `
10- - ` elasticsearch_metrics.imps.elastic6 `
9+ - ` elasticsearch_metrics.imps.elastic8 ` (an implementation with elasticsearch 8)
10+ - ` elasticsearch_metrics.imps.elastic6 ` (an implementation with elasticsearch 6; deprecated)
1111- ...
1212
1313## Pre-requisites
@@ -58,7 +58,7 @@ class UsageRecord(EventRecord):
5858 item_id: int
5959
6060 class Index :
61- using = " my-es8-backend" # optional if only one backend
61+ using = " my-es8-backend" # backend name -- required if multiple backends use the same imp
6262```
6363
6464Either enable autosetup...
@@ -98,19 +98,26 @@ UsageRecord.search_timeseries_range(datetime.date(2030, 1, 1), datetime.date(203
9898
9999## Timeseries indexes
100100
101- By default, behind the scenes, a new elasticsearch index is created for each record type for each month
102- in which a record is saved (using UTC timezone). You can set a default change the per-index timespan by
103- setting ` Meta.timedepth ` on the record type .
101+ By default, behind the scenes, a new elasticsearch index is created for each record type for each day
102+ in which a record is saved (using UTC timezone). You can change this for a record type by setting
103+ ` Meta.timedepth ` , or change the default timedepth with the setting ` DJELME_DEFAULT_TIMEDEPTH ` (see below) .
104104
105- - index per day, '...YYYY_MM_DD...': ` timedepth = 3 `
106- - index per month, '...YYYY_MM...': ` timedepth = 2 `
107- - index per year, '...YYYY...': ` timedepth = 1 `
105+ ``` python
106+ class MyEventWithMonthlyIndexes (EventRecord ):
107+ class Meta :
108+ timedepth = 2 # year and month
109+ ```
110+
111+ - index per year: ` timedepth = 1 `
112+ - index per month: ` timedepth = 2 `
113+ - index per day: ` timedepth = 3 ` (default)
114+ - index per hour: ` timedepth = 4 `
108115
109116
110117## Index settings
111118
112- You can configure the index template settings by setting
113- ` Index.settings ` on a record type.
119+ You can configure the index settings that will be set on the index template
120+ and used for each new timeseries index with ` Index.settings ` on a record type.
114121
115122``` python
116123class UsageRecord (EventRecord ):
@@ -166,27 +173,6 @@ class UsageRecord(MyBaseMetric):
166173 app_label = " myapp"
167174```
168175
169- ## Optional factory_boy integration
170-
171- ``` python
172- import factory
173- from elasticsearch_metrics.factory import MetricFactory
174-
175- from ..myapp.metrics import MyMetric
176-
177-
178- class MyMetricFactory (MetricFactory ):
179- my_int = factory.Faker(" pyint" )
180-
181- class Meta :
182- model = MyMetric
183-
184-
185- def test_something ():
186- metric = MyMetricFactory() # index metric in ES
187- assert isinstance (metric.my_int, int )
188- ```
189-
190176## Configuration
191177
192178* ` DJELME_BACKENDS ` : Named backends for storing or searching records from your django app
@@ -213,9 +199,9 @@ def test_something():
213199* ` DJELME_DEFAULT_TIMEDEPTH ` : Set the granularity of timeseries indexes by the number of "time parts" in index names
214200 ```
215201 DJELME_DEFAULT_TIMEDEPTH = 1 # yearly indexes; YYYY
216- DJELME_DEFAULT_TIMEDEPTH = 2 # monthly indexes; YYYY_MM
217- DJELME_DEFAULT_TIMEDEPTH = 3 # daily indexes; YYYY_MM_DD (this is the default)
218- DJELME_DEFAULT_TIMEDEPTH = 4 # hourly indexes; YYYY_MM_DD_HH
202+ DJELME_DEFAULT_TIMEDEPTH = 2 # monthly indexes; YYYY.MM
203+ DJELME_DEFAULT_TIMEDEPTH = 3 # daily indexes; YYYY.MM.DD (this is the default)
204+ DJELME_DEFAULT_TIMEDEPTH = 4 # hourly indexes; YYYY.MM.DD.HH
219205 ```
220206 you can also set `Meta.timedepth` on a specific record type; this will take precedence
221207
0 commit comments