-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' for release 2.4.9
- Loading branch information
Showing
20 changed files
with
143 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
2.4.8 | ||
2.4.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'json' | ||
|
||
class CustomAggregationService | ||
|
||
## | ||
# Run any additional custom aggregations related to the given statistic type, if any | ||
## | ||
def call(statistic_index, statistic_type, start_date, end_date, custom_query, results) | ||
if statistic_type and start_date and end_date | ||
stat_index = StatisticIndex.find_by(es_type_key: statistic_index) | ||
stat_type = StatisticType.find_by(statistic_index_id: stat_index.id, key: statistic_type) | ||
client = Elasticsearch::Model.client | ||
stat_type.statistic_custom_aggregations.each do |custom| | ||
|
||
query = sprintf(custom.query, {aggs_name: custom.field, start_date: start_date, end_date: end_date}) | ||
|
||
if custom_query and !custom_query.empty? | ||
# Here, a custom query was provided with the original request (eg: filter by subtype) | ||
# so we try to apply this custom filter to the current custom aggregation. | ||
# | ||
# The requested model mapping (ie. found in StatisticCustomAggregation.es_index > es_type) must have defined | ||
# these fields in the indexed json, otherwise the returned value will probably not be what is expected. | ||
# | ||
# As an implementation exemple, you can take a look at Availability (indexed as fablab/availabilities) | ||
# and witch will run custom filters on the fields 'date' and 'subType'. Other custom filters will return 0 | ||
# as they are not relevant with this kind of custom aggregation. | ||
query = JSON.parse(query) | ||
custom_query = JSON.parse(custom_query) | ||
|
||
exclude = custom_query.delete('exclude') | ||
if exclude | ||
query = {query: { filtered: { query: query['query'], filter: { not: { term: custom_query['match'] } } } }, aggregations: query['aggregations'], size: query['size']} | ||
else | ||
query['query']['bool']['must'].push(custom_query) | ||
end | ||
query = query.to_json | ||
end | ||
|
||
c_res = client.search(index: custom.es_index, type: custom.es_type, body: query) | ||
results['aggregations'][custom.field] = c_res['aggregations'][custom.field] | ||
end | ||
end | ||
results | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters