Skip to content

Commit

Permalink
Fix searchkick mappings for metadata (#870)
Browse files Browse the repository at this point in the history
* chore: update searchkick mappings for metadata to index fields ending in _date as date and other fields as both text and numeric

* chore: add in SearchKick default string_template dynamic mapping

* chore: remove shards setting
  • Loading branch information
ericenns authored Dec 13, 2024
1 parent 9fc4e2e commit 9da7f6c
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 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,51 @@ class Sample < ApplicationRecord
acts_as_paranoid

searchkick \
merge_mappings: true,
mappings: {
dynamic_templates: [
{
string_template: {
match: '*',
match_mapping_type: 'string',
mapping: {
fields: {
analyzed: {
analyzer: 'searchkick_index',
index: true,
type: 'text'
}
},
ignore_above: 30_000,
type: 'keyword'
}
}
},
{
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
}
}
}
}
}
]
},
deep_paging: true,
text_middle: %i[name puid]

Expand Down Expand Up @@ -91,11 +136,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 9da7f6c

Please sign in to comment.