Skip to content

Commit

Permalink
chore: update searchkick mappings for metadata to index fields ending…
Browse files Browse the repository at this point in the history
… in _date as date and other fields as both text and numeric
  • Loading branch information
ericenns committed Dec 13, 2024
1 parent 9fc4e2e commit 44bb136
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions app/models/sample.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# entity class for Sample
class Sample < ApplicationRecord
class Sample < ApplicationRecord # rubocop:disable Metrics/ClassLength
include MetadataSortable
include HasPuid
include History
Expand All @@ -12,6 +12,35 @@ class Sample < ApplicationRecord
acts_as_paranoid

searchkick \
merge_mappings: true,
mappings: { dynamic_templates: [
{
metadata_dates: {
path_match: 'metadata.*_date',
mapping: {
type: 'date',
ignore_malformed: true
}
}
}, {
metadata_non_dates: {
path_match: 'metadata.*',
path_unmatch: 'metadata.*_date',
mapping: {
type: 'text',
fields: {
numeric: {
type: 'double',
ignore_malformed: true
}
}
}
}
}
] },
settings: {
number_of_shards: 1
},
deep_paging: true,
text_middle: %i[name puid]

Expand Down Expand Up @@ -91,11 +120,11 @@ def search_data
name: name,
puid: puid,
project_id: project_id,
metadata: metadata.as_json,
metadata: metadata.transform_keys { |k| k.gsub('.', '___') },
created_at: created_at,
updated_at: updated_at,
attachments_updated_at: attachments_updated_at
}
}.compact
end

def should_index?
Expand Down

0 comments on commit 44bb136

Please sign in to comment.