Commit 74ad1d1c authored by Nick Thomas's avatar Nick Thomas

Merge branch '118662-drop-support-es-v5-support-v7' into 'master'

Add support for ES7 & Drop suport for ES5

Closes #196503

See merge request gitlab-org/gitlab!22859
parents 131ff56d 4d3c8c2e
...@@ -213,7 +213,7 @@ ...@@ -213,7 +213,7 @@
- name: postgres:9.6 - name: postgres:9.6
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"] command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
- name: redis:alpine - name: redis:alpine
- name: elasticsearch:5.6.12 - name: elasticsearch:6.4.2
.use-pg10-ee: .use-pg10-ee:
image: "registry.gitlab.com/gitlab-org/gitlab-build-images:ruby-2.6.5-golang-1.12-git-2.24-lfs-2.9-chrome-73.0-node-12.x-yarn-1.16-postgresql-10-graphicsmagick-1.3.33" image: "registry.gitlab.com/gitlab-org/gitlab-build-images:ruby-2.6.5-golang-1.12-git-2.24-lfs-2.9-chrome-73.0-node-12.x-yarn-1.16-postgresql-10-graphicsmagick-1.3.33"
...@@ -221,7 +221,7 @@ ...@@ -221,7 +221,7 @@
- name: postgres:10.9 - name: postgres:10.9
command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"] command: ["postgres", "-c", "fsync=off", "-c", "synchronous_commit=off", "-c", "full_page_writes=off"]
- name: redis:alpine - name: redis:alpine
- name: elasticsearch:5.6.12 - name: elasticsearch:6.4.2
.only-ee: .only-ee:
only: only:
......
---
title: Drop support for ES5 add support for ES7
merge_request: 22859
author:
type: added
...@@ -18,6 +18,32 @@ Gitlab.ee do ...@@ -18,6 +18,32 @@ Gitlab.ee do
Elasticsearch::Model::ClassMethods.prepend GemExtensions::Elasticsearch::Model::Client Elasticsearch::Model::ClassMethods.prepend GemExtensions::Elasticsearch::Model::Client
Elasticsearch::Model.singleton_class.prepend GemExtensions::Elasticsearch::Model::Client Elasticsearch::Model.singleton_class.prepend GemExtensions::Elasticsearch::Model::Client
# This monkey patch cannot be handled by prepend like the above since this
# module is included into other classes.
module Elasticsearch
module Model
module Response
module Base
if Gem::Version.new(Elasticsearch::Model::VERSION) >= Gem::Version.new('7.0.0')
raise "elasticsearch-model was upgraded, please remove this monkey patch in #{__FILE__}"
end
# Handle ES7 API where total is returned as an object. This
# change is taken from the V7 gem
# https://github.com/elastic/elasticsearch-rails/commit/9c40f630e1b549f0b7889fe33dcd826b485af6fc
# and can be removed when we upgrade the gem to V7
def total
if response.response['hits']['total'].respond_to?(:keys)
response.response['hits']['total']['value']
else
response.response['hits']['total']
end
end
end
end
end
end
### Modified from elasticsearch-model/lib/elasticsearch/model.rb ### Modified from elasticsearch-model/lib/elasticsearch/model.rb
[ [
......
...@@ -17,9 +17,10 @@ special searches: ...@@ -17,9 +17,10 @@ special searches:
| GitLab version | Elasticsearch version | | GitLab version | Elasticsearch version |
| -------------- | --------------------- | | -------------- | --------------------- |
| GitLab Enterprise Edition 8.4 - 8.17 | Elasticsearch 2.4 with [Delete By Query Plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/2.4/plugins-delete-by-query.html) installed | | GitLab Enterprise Edition 8.4 - 8.17 | Elasticsearch 2.4 with [Delete By Query Plugin](https://www.elastic.co/guide/en/elasticsearch/plugins/2.4/plugins-delete-by-query.html) installed |
| GitLab Enterprise Edition 9.0 - 11.4 | Elasticsearch 5.1 - 5.5 | | GitLab Enterprise Edition 9.0 - 11.4 | Elasticsearch 5.1 - 5.5 |
| GitLab Enterprise Edition 11.5+ | Elasticsearch 5.6 - 6.x | | GitLab Enterprise Edition 11.5 - 12.6 | Elasticsearch 5.6 - 6.x |
| GitLab Enterprise Edition 12.7+ | Elasticsearch 6.x - 7.x |
## Installing Elasticsearch ## Installing Elasticsearch
......
...@@ -21,7 +21,7 @@ module Elastic ...@@ -21,7 +21,7 @@ module Elastic
analyzer: { analyzer: {
default: { default: {
tokenizer: 'standard', tokenizer: 'standard',
filter: %w(standard lowercase my_stemmer) filter: %w(lowercase my_stemmer)
}, },
my_ngram_analyzer: { my_ngram_analyzer: {
tokenizer: 'my_ngram_tokenizer', tokenizer: 'my_ngram_tokenizer',
......
...@@ -26,20 +26,29 @@ module Gitlab ...@@ -26,20 +26,29 @@ module Gitlab
client = proxy.client client = proxy.client
index_name = proxy.index_name index_name = proxy.index_name
# ES5.6 needs a setting enabled to support JOIN datatypes that ES6 does not support... create_index_options = {
if Gitlab::VersionInfo.parse(client.info['version']['number']) < Gitlab::VersionInfo.new(6) index: index_name,
settings['index.mapping.single_type'] = true body: {
settings: settings.to_hash,
mappings: mappings.to_hash
}
}
# include_type_name defaults to false in ES7. This will ensure ES7
# behaves like ES6 when creating mappings. See
# https://www.elastic.co/blog/moving-from-types-to-typeless-apis-in-elasticsearch-7-0
# for more information. We also can't set this for any versions before
# 6.8 as this parameter was not supported. Since it defaults to true in
# all 6.x it's safe to only set it for 7.x.
if Gitlab::VersionInfo.parse(client.info['version']['number']).major == 7
create_index_options[:include_type_name] = true
end end
if client.indices.exists? index: index_name if client.indices.exists? index: index_name
client.indices.delete index: index_name client.indices.delete index: index_name
end end
client.indices.create index: index_name, client.indices.create create_index_options
body: {
settings: settings.to_hash,
mappings: mappings.to_hash
}
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -21,10 +21,10 @@ module SystemCheck ...@@ -21,10 +21,10 @@ module SystemCheck
def check? def check?
case self.class.current_version.major case self.class.current_version.major
when 5
!(1..5).cover?(self.class.current_version.minor)
when 6 when 6
true true
when 7
true
else else
false false
end end
......
...@@ -32,11 +32,12 @@ describe SystemCheck::App::ElasticsearchCheck do ...@@ -32,11 +32,12 @@ describe SystemCheck::App::ElasticsearchCheck do
where(:version, :result) do where(:version, :result) do
'2.3.0' | false '2.3.0' | false
'5.3.1' | false '5.3.1' | false
'5.6.0' | true '5.6.0' | false
'5.6.6' | true '5.6.6' | false
'6.0.0' | true '6.0.0' | true
'6.3.4' | true '6.4.2' | true
'7.1.0' | false '7.1.0' | true
'7.5.1' | true
end end
with_them do with_them do
......
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