Commit fdbf045d authored by Dylan Griffith's avatar Dylan Griffith

Merge branch '349124-add-meta-field-to-indices-mappings' into 'master'

Advanced Search: Add meta field to indices mapping

See merge request gitlab-org/gitlab!77241
parents d746c810 fdf5d094
...@@ -247,6 +247,12 @@ module Gitlab ...@@ -247,6 +247,12 @@ module Gitlab
client.indices.put_mapping(index: index_name || target_index_name, body: mappings) client.indices.put_mapping(index: index_name || target_index_name, body: mappings)
end end
def get_meta(index_name: nil)
index = target_index_name(target: index_name)
mappings = client.indices.get_mapping(index: index)
mappings.dig(index, 'mappings', '_meta')
end
def switch_alias(from: target_index_name, alias_name: target_name, to:) def switch_alias(from: target_index_name, alias_name: target_name, to:)
actions = [ actions = [
{ {
...@@ -297,11 +303,19 @@ module Gitlab ...@@ -297,11 +303,19 @@ module Gitlab
settings.merge!(options[:settings]) if options[:settings] settings.merge!(options[:settings]) if options[:settings]
mappings.merge!(options[:mappings]) if options[:mappings] mappings.merge!(options[:mappings]) if options[:mappings]
meta_info = {
doc: {
_meta: {
created_by: Gitlab::VERSION
}
}
}
create_index_options = { create_index_options = {
index: index_name, index: index_name,
body: { body: {
settings: settings, settings: settings,
mappings: mappings mappings: mappings.deep_merge(meta_info)
} }
}.merge(additional_index_options) }.merge(additional_index_options)
......
...@@ -386,4 +386,12 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do ...@@ -386,4 +386,12 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do
expect { subject }.not_to raise_exception expect { subject }.not_to raise_exception
end end
end end
describe '#get_meta', :elastic do
subject { helper.get_meta }
it 'returns version in meta field' do
is_expected.to include('created_by' => Gitlab::VERSION)
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment