Skip to content

Commit

Permalink
fix too many buckets exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Mar 10, 2020
1 parent 09b41e0 commit 5f73e52
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/controllers/export_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def repositories
logger.warn "Exporting #{clients.length} repositories."

# Get doi counts via DOIs query and combine next to clients.
response = Doi.query(nil, state: "registered,findable", page: { size: 0, number: 1 }, totals_agg: "client")
response = Doi.query(nil, state: "registered,findable", page: { size: 0, number: 1 }, totals_agg: "client_export")

client_totals = {}
totals_buckets = response.response.aggregations.clients_totals.buckets
Expand Down Expand Up @@ -286,9 +286,9 @@ def repositories
created: export_date(client.created),
modified: export_date(client.updated),
deleted: client.deleted_at.present? ? export_date(client.deleted_at) : nil,
doisCountCurrentYear: client_totals[client.uid] ? client_totals[client.uid]["this_year"] : nil,
doisCountPreviousYear: client_totals[client.uid] ? client_totals[client.uid]["last_year"] : nil,
doisCountTotal: client_totals[client.uid] ? client_totals[client.uid]["count"] : nil
doisCountCurrentYear: client_totals[client.uid] ? client_totals[client.uid]["this_year"] : 0,
doisCountPreviousYear: client_totals[client.uid] ? client_totals[client.uid]["last_year"] : 0,
doisCountTotal: client_totals[client.uid] ? client_totals[client.uid]["count"] : 0
}.values

csv += CSV.generate_line row
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def query(query, options={})
aggregations = provider_aggregations
elsif options[:totals_agg] == "client"
aggregations = client_aggregations
elsif options[:totals_agg] == "client_export"
aggregations = client_export_aggregations
elsif options[:totals_agg] == "prefix"
aggregations = prefix_aggregations
else
Expand Down
14 changes: 14 additions & 0 deletions app/models/doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ def self.client_aggregations
{ clients_totals: { terms: { field: 'client_id', size: ::Client.__elasticsearch__.count, min_doc_count: 1 }, aggs: sub_aggregations } }
end

def self.client_export_aggregations
{ clients_totals: { terms: { field: 'client_id', size: ::Client.__elasticsearch__.count, min_doc_count: 1 }, aggs: export_sub_aggregations } }
end

def self.prefix_aggregations
{ prefixes_totals: { terms: { field: 'prefix', size: ::Prefix.count, min_doc_count: 1 }, aggs: sub_aggregations } }
end
Expand All @@ -593,6 +597,14 @@ def self.sub_aggregations
}
end

def self.export_sub_aggregations
{
this_year: { date_range: { field: 'created', ranges: { from: "now/y", to: "now/d" } } },
last_year: { date_range: { field: 'created', ranges: { from: "now-1y/y", to: "now/y-1d" } } },
two_years_ago: { date_range: { field: 'created', ranges: { from: "now-2y/y", to: "now-1y/y-1d" } } }
}
end

def self.query_fields
["uid^50", "related_identifiers.relatedIdentifier^3", "funding_references.relatedIdentifier^3", "container.identifier^3", 'titles.title^3', 'creator_names^3', 'creators.name^3', 'creators.id^3', 'publisher^3', 'descriptions.description^3', 'types.resourceTypeGeneral^3', 'subjects.subject^3', 'client.uid^3', 'provider.uid^3', '_all']
end
Expand Down Expand Up @@ -667,6 +679,8 @@ def self.query(query, options={})
aggregations = provider_aggregations
elsif options[:totals_agg] == "client"
aggregations = client_aggregations
elsif options[:totals_agg] == "client_export"
aggregations = client_export_aggregations
elsif options[:totals_agg] == "prefix"
aggregations = prefix_aggregations
else
Expand Down

0 comments on commit 5f73e52

Please sign in to comment.