Skip to content
Snippets Groups Projects
Commit 5caac54a authored by Dmitry Gruzd's avatar Dmitry Gruzd Committed by GitLab Release Tools Bot
Browse files

Fix mappings errors for ES6.8

parent c5dd9bf2
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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!
Loading
Loading
Loading
Loading
@@ -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:)
Loading
Loading
@@ -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)
Loading
Loading
Loading
Loading
@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment