Skip to content

Commit

Permalink
fix index for citation_year histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
kjgarza committed Aug 2, 2019
1 parent f3c1a32 commit 85b4f89
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
4 changes: 2 additions & 2 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def facet_by_source(arr)

def facet_citations_by_year(hash)
arr = hash.dig('years', 'buckets').map do |h|
year = h['key_as_string'][0..3].to_i
title = h['key_as_string'][0..3]
year = h['key']
title = h['key'].to_i.to_s

{
'id' => year,
Expand Down
24 changes: 19 additions & 5 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Event < ActiveRecord::Base
indexes :indexed_at, type: :date
indexes :occurred_at, type: :date
indexes :citation_id, type: :keyword
indexes :citation_year, type: :keyword
indexes :citation_year, type: :integer
indexes :cache_key, type: :keyword
end

Expand Down Expand Up @@ -232,11 +232,15 @@ def self.metrics_aggregations
}
}

views_filter = {script: {script: "#{VIEWS_RELATION_TYPES}.contains(doc['relation_type_id'].value) && doc['source_id'].value == 'datacite-usage' && doc['occurred_at'].value.getMillis() >= doc['obj.datePublished'].value.getMillis() && doc['occurred_at'].value.getMillis() < new Date().getTime()"}}

downloads_filter = {script: {script: "#{DOWNLOADS_RELATION_TYPES}.contains(doc['relation_type_id'].value) && doc['source_id'].value == 'datacite-usage' && doc['occurred_at'].value.getMillis() >= doc['obj.datePublished'].value.getMillis() && doc['occurred_at'].value.getMillis() < new Date().getTime()"} }

{
citations_histogram: {
filter: {script: {script: "#{INCLUDED_RELATION_TYPES}.contains(doc['relation_type_id'].value)"}
},
aggs: { years: { date_histogram: { field: 'citation_year', interval: 'year', min_doc_count: 1 }, aggs: { "total_by_year" => { sum: { field: 'total' }}}},"sum_distribution"=>sum_year_distribution}
aggs: { years: { histogram: { field: 'citation_year', interval: 1 , min_doc_count: 1 }, aggs: { "total_by_year" => { sum: { field: 'total' }}}},"sum_distribution"=>sum_year_distribution}
},
citations: {
filter: {script: {script: "#{INCLUDED_RELATION_TYPES}.contains(doc['relation_type_id'].value)"}
Expand All @@ -246,15 +250,25 @@ def self.metrics_aggregations
}}
},
views: {
filter: {script: {script: "#{VIEWS_RELATION_TYPES}.contains(doc['relation_type_id'].value) && doc['source_id'].value == 'datacite-usage' && doc['occurred_at'].value.getMillis() >= doc['obj.datePublished'].value.getMillis() && doc['occurred_at'].value.getMillis() < new Date().getTime()"}
},
filter: views_filter,
aggs: { dois: {
terms: { field: 'obj_id', size: 50, min_doc_count: 1 }
}}
},
views_histogram: {
filter: views_filter,
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
}
},
downloads: {
filter: {script: {script: "#{DOWNLOADS_RELATION_TYPES}.contains(doc['relation_type_id'].value) && doc['source_id'].value == 'datacite-usage' && doc['occurred_at'].value.getMillis() >= doc['obj.datePublished'].value.getMillis() && doc['occurred_at'].value.getMillis() < new Date().getTime()"}
filter: downloads_filter,
aggs: { dois: {
terms: { field: 'obj_id', size: 50, min_doc_count: 1 }
}}
},
downloads_histogram: {
filter: downloads_filter,
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
}
Expand Down

0 comments on commit 85b4f89

Please sign in to comment.