Commit 5caac54a authored by Dmitry Gruzd's avatar Dmitry Gruzd Committed by GitLab Release Tools Bot

Fix mappings errors for ES6.8

See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/85633

EE: true
Changelog: fixed
parent c5dd9bf2
......@@ -46,11 +46,7 @@ class AddUpvotesToIssues < Elastic::Migration
private
def update_mappings!
client.indices.put_mapping index: index_name, body: {
properties: {
upvotes: { type: 'integer' }
}
}
helper.update_mapping(index_name: index_name, mappings: { properties: { upvotes: { type: 'integer' } } })
end
def process_batch!
......
......@@ -261,8 +261,15 @@ module Gitlab
def get_mapping(index_name: nil)
index = target_index_name(target: index_name)
mappings = client.indices.get_mapping(index: index)
mappings.dig(index, 'mappings', 'properties')
mappings = client.indices.get_mapping({ index: index })
# The check for version 6 (and the spec testing this code) should be removed when support for
# Elasticsearch v6.8 is removed
if Gitlab::VersionInfo.parse(client.info['version']['number']).major == 6
mappings.dig(index, 'mappings', 'doc', 'properties')
else
mappings.dig(index, 'mappings', 'properties')
end
end
def update_settings(index_name: nil, settings:)
......@@ -270,7 +277,12 @@ module Gitlab
end
def update_mapping(index_name: nil, mappings:)
client.indices.put_mapping(index: index_name || target_index_name, body: mappings)
options = {
index: index_name || target_index_name,
body: mappings
}
options[:type] = 'doc' if Gitlab::VersionInfo.parse(client.info['version']['number']).major == 6
client.indices.put_mapping(options)
end
def get_meta(index_name: nil)
......
......@@ -520,4 +520,34 @@ RSpec.describe Gitlab::Elastic::Helper, :request_store do
end
end
end
describe '#get_mapping' do
let(:index_name) { Issue.__elasticsearch__.index_name }
subject { helper.get_mapping(index_name: index_name) }
it 'reads mappings from client', :elastic do
is_expected.not_to be_nil
end
context 'when using elasticsearch version 6.8' do
before do
info = {
'version' => {
'number' => '6.8.1',
'build_type' => 'docker',
'lucene_version' => '8.6.2'
}
}
mapping = { "#{index_name}": { mappings: { doc: { properties: { test: 1 } } } } }.with_indifferent_access
allow(Gitlab::Elastic::Helper.default.client).to receive(:info).and_return(info)
allow(helper.client.indices).to receive(:get_mapping).and_return(mapping)
end
it 'reads mappings from client' do
is_expected.not_to be_nil
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