diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 76010892a..e6881e75f 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -137,10 +137,10 @@ def index sources = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_source(response.response.aggregations.sources.buckets) : nil prefixes = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_source(response.response.aggregations.prefixes.buckets) : nil - citation_types = total.positive? && aggregations.include?("advanced_aggregations") ? facet_by_citation_type(response.response.aggregations.citation_types.buckets) : nil - relation_types = total.positive? && aggregations.include?("advanced_aggregations") ? facet_by_relation_type(response.response.aggregations.relation_types.buckets) : nil - registrants = total.positive? && aggregations.include?("advanced_aggregations") ? facet_by_registrants(response.response.aggregations.registrants.buckets) : nil - pairings = total.positive? && aggregations.include?("advanced_aggregations") ? facet_by_pairings(response.response.aggregations.pairings.buckets) : nil + citation_types = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_citation_type(response.response.aggregations.citation_types.buckets) : nil + relation_types = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_relation_type(response.response.aggregations.relation_types.buckets) : nil + registrants = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_registrants(response.response.aggregations.registrants.buckets) : nil + pairings = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_pairings(response.response.aggregations.pairings.buckets) : nil dois = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_by_dois(response.response.aggregations.dois.buckets) : nil dois_usage = total.positive? ? EventsQuery.new.usage(params[:doi]) : nil # dois_citations = total.positive? && aggregations.blank? || aggregations.include?("query_aggregations") ? facet_citations_by_year_v1(response.response.aggregations.dois_citations) : nil diff --git a/app/models/event.rb b/app/models/event.rb index d580a6c35..7cbec81d6 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -201,9 +201,19 @@ def self.query_fields end def self.query_aggregations + sum_distribution = { + sum_bucket: { + buckets_path: "year_months>total_by_year_month" + } + } + { sources: { terms: { field: "source_id", size: 50, min_doc_count: 1 } }, prefixes: { terms: { field: "prefix", size: 50, min_doc_count: 1 } }, + registrants: { terms: { field: "registrant_id", size: 50, min_doc_count: 1 }, aggs: { year: { date_histogram: { field: "occurred_at", interval: "year", min_doc_count: 1 }, aggs: { "total_by_year" => { sum: { field: "total" } } } } } }, + pairings: { terms: { field: "registrant_id", size: 50, min_doc_count: 1 }, aggs: { recipient: { terms: { field: "registrant_id", size: 50, min_doc_count: 1 }, aggs: { "total" => { sum: { field: "total" } } } } } }, + citation_types: { terms: { field: "citation_type", size: 50, min_doc_count: 1 }, aggs: { year_months: { date_histogram: { field: "occurred_at", interval: "month", min_doc_count: 1 }, aggs: { "total_by_year_month" => { sum: { field: "total" } } } } } }, + relation_types: { terms: { field: "relation_type_id", size: 50, min_doc_count: 1 }, aggs: { year_months: { date_histogram: { field: "occurred_at", interval: "month", min_doc_count: 1 }, aggs: { "total_by_year_month" => { sum: { field: "total" } } } }, "sum_distribution" => sum_distribution } }, dois: { terms: { field: "obj_id", size: 50, min_doc_count: 1 }, aggs: { relation_types: { terms: { field: "relation_type_id", size: 50, min_doc_count: 1 }, aggs: { "total_by_type" => { sum: { field: "total" } } } } } } } end @@ -249,17 +259,7 @@ def self.monthly_histogram_aggregation def self.advanced_aggregations - sum_distribution = { - sum_bucket: { - buckets_path: "year_months>total_by_year_month" - } - } - { - registrants: { terms: { field: "registrant_id", size: 50, min_doc_count: 1 }, aggs: { year: { date_histogram: { field: "occurred_at", interval: "year", min_doc_count: 1 }, aggs: { "total_by_year" => { sum: { field: "total" } } } } } }, - pairings: { terms: { field: "registrant_id", size: 50, min_doc_count: 1 }, aggs: { recipient: { terms: { field: "registrant_id", size: 50, min_doc_count: 1 }, aggs: { "total" => { sum: { field: "total" } } } } } }, - citation_types: { terms: { field: "citation_type", size: 50, min_doc_count: 1 }, aggs: { year_months: { date_histogram: { field: "occurred_at", interval: "month", min_doc_count: 1 }, aggs: { "total_by_year_month" => { sum: { field: "total" } } } } } }, - relation_types: { terms: { field: "relation_type_id", size: 50, min_doc_count: 1 }, aggs: { year_months: { date_histogram: { field: "occurred_at", interval: "month", min_doc_count: 1 }, aggs: { "total_by_year_month" => { sum: { field: "total" } } } }, "sum_distribution" => sum_distribution } }, unique_obj_count: { cardinality: { field: "obj_id" } }, unique_subj_count: { cardinality: { field: "subj_id" } } } diff --git a/spec/concerns/indexable_spec.rb b/spec/concerns/indexable_spec.rb index 8d6a89523..422f2bc97 100644 --- a/spec/concerns/indexable_spec.rb +++ b/spec/concerns/indexable_spec.rb @@ -169,10 +169,10 @@ aggregations = Event.get_aggregations_hash({aggregations:""}) expect(aggregations[:sources]).not_to be_nil expect(aggregations[:prefixes]).not_to be_nil - expect(aggregations[:citation_types]).to be_nil - expect(aggregations[:relation_types]).to be_nil - expect(aggregations[:registrants]).to be_nil - expect(aggregations[:pairings]).to be_nil + expect(aggregations[:citation_types]).not_to be_nil + expect(aggregations[:relation_types]).not_to be_nil + expect(aggregations[:registrants]).not_to be_nil + expect(aggregations[:pairings]).not_to be_nil # expect(aggregations[:dois_usage]).not_to be_nil expect(aggregations[:citations_histogram]).to be_nil expect(aggregations[:citations]).to be_nil @@ -182,10 +182,10 @@ aggregations = Event.get_aggregations_hash({aggregations:"query_aggregations,citation_count_aggregation"}) expect(aggregations[:sources]).not_to be_nil expect(aggregations[:prefixes]).not_to be_nil - expect(aggregations[:citation_types]).to be_nil - expect(aggregations[:relation_types]).to be_nil - expect(aggregations[:registrants]).to be_nil - expect(aggregations[:pairings]).to be_nil + expect(aggregations[:citation_types]).not_to be_nil + expect(aggregations[:relation_types]).not_to be_nil + expect(aggregations[:registrants]).not_to be_nil + expect(aggregations[:pairings]).not_to be_nil expect(aggregations[:dois]).not_to be_nil # expect(aggregations[:dois_usage]).not_to be_nil expect(aggregations[:citations]).not_to be_nil