Commit 2ab42c0d authored by Ruben Davila's avatar Ruben Davila

Merge branch 'master' into ce-to-ee

parents 78cfb54c daeeba0b
...@@ -6,7 +6,7 @@ module Elastic ...@@ -6,7 +6,7 @@ module Elastic
included do included do
include Elasticsearch::Model include Elasticsearch::Model
index_name [Rails.application.class.parent_name.downcase, self.name.downcase, Rails.env].join('-') index_name [Rails.application.class.parent_name.downcase, Rails.env].join('-')
settings \ settings \
index: { index: {
...@@ -92,7 +92,7 @@ module Elastic ...@@ -92,7 +92,7 @@ module Elastic
end end
query_hash[:sort] = [ query_hash[:sort] = [
{ updated_at_sort: { order: :desc, mode: :min } }, { updated_at: { order: :desc } },
:_score :_score
] ]
......
...@@ -22,8 +22,6 @@ module Elastic ...@@ -22,8 +22,6 @@ module Elastic
indexes :assignee_id, type: :integer indexes :assignee_id, type: :integer
indexes :confidential, type: :boolean indexes :confidential, type: :boolean
indexes :updated_at_sort, type: :date, index: :not_analyzed
end end
def as_indexed_json(options = {}) def as_indexed_json(options = {})
...@@ -35,9 +33,6 @@ module Elastic ...@@ -35,9 +33,6 @@ module Elastic
data[attr.to_s] = self.send(attr) data[attr.to_s] = self.send(attr)
end end
data['project'] = { 'id' => project_id }
data['author'] = { 'id' => author_id }
data['updated_at_sort'] = updated_at
data data
end end
......
...@@ -25,8 +25,6 @@ module Elastic ...@@ -25,8 +25,6 @@ module Elastic
indexes :source_project_id, type: :integer indexes :source_project_id, type: :integer
indexes :target_project_id, type: :integer indexes :target_project_id, type: :integer
indexes :author_id, type: :integer indexes :author_id, type: :integer
indexes :updated_at_sort, type: :string, index: 'not_analyzed'
end end
def as_indexed_json(options = {}) def as_indexed_json(options = {})
...@@ -51,8 +49,7 @@ module Elastic ...@@ -51,8 +49,7 @@ module Elastic
].each do |attr| ].each do |attr|
data[attr.to_s] = self.send(attr) data[attr.to_s] = self.send(attr)
end end
data['updated_at_sort'] = updated_at
data data
end end
......
...@@ -13,14 +13,13 @@ module Elastic ...@@ -13,14 +13,13 @@ module Elastic
index_options: 'offsets' index_options: 'offsets'
indexes :project_id, type: :integer indexes :project_id, type: :integer
indexes :created_at, type: :date indexes :created_at, type: :date
indexes :updated_at, type: :date
indexes :updated_at_sort, type: :string, index: 'not_analyzed'
end end
def as_indexed_json(options = {}) def as_indexed_json(options = {})
as_json( as_json(
only: [:id, :title, :description, :project_id, :created_at] only: [:id, :title, :description, :project_id, :created_at, :updated_at]
).merge({ updated_at_sort: updated_at }) )
end end
def self.elastic_search(query, options: {}) def self.elastic_search(query, options: {})
......
...@@ -11,14 +11,13 @@ module Elastic ...@@ -11,14 +11,13 @@ module Elastic
index_options: 'offsets' index_options: 'offsets'
indexes :project_id, type: :integer indexes :project_id, type: :integer
indexes :created_at, type: :date indexes :created_at, type: :date
indexes :updated_at, type: :date
indexes :issue do indexes :issue do
indexes :assignee_id, type: :integer indexes :assignee_id, type: :integer
indexes :author_id, type: :integer indexes :author_id, type: :integer
indexes :confidential, type: :boolean indexes :confidential, type: :boolean
end end
indexes :updated_at_sort, type: :string, index: 'not_analyzed'
end end
def as_indexed_json(options = {}) def as_indexed_json(options = {})
...@@ -26,7 +25,7 @@ module Elastic ...@@ -26,7 +25,7 @@ module Elastic
# We don't use as_json(only: ...) because it calls all virtual and serialized attributtes # We don't use as_json(only: ...) because it calls all virtual and serialized attributtes
# https://gitlab.com/gitlab-org/gitlab-ee/issues/349 # https://gitlab.com/gitlab-org/gitlab-ee/issues/349
[:id, :note, :project_id, :created_at].each do |attr| [:id, :note, :project_id, :created_at, :updated_at].each do |attr|
data[attr.to_s] = self.send(attr) data[attr.to_s] = self.send(attr)
end end
...@@ -38,7 +37,6 @@ module Elastic ...@@ -38,7 +37,6 @@ module Elastic
} }
end end
data['updated_at_sort'] = updated_at
data data
end end
...@@ -62,7 +60,7 @@ module Elastic ...@@ -62,7 +60,7 @@ module Elastic
query_hash = confidentiality_filter(query_hash, options[:current_user]) query_hash = confidentiality_filter(query_hash, options[:current_user])
query_hash[:sort] = [ query_hash[:sort] = [
{ updated_at_sort: { order: :desc, mode: :min } }, { updated_at: { order: :desc } },
:_score :_score
] ]
......
...@@ -22,6 +22,7 @@ module Elastic ...@@ -22,6 +22,7 @@ module Elastic
indexes :namespace_id, type: :integer indexes :namespace_id, type: :integer
indexes :created_at, type: :date indexes :created_at, type: :date
indexes :updated_at, type: :date
indexes :archived, type: :boolean indexes :archived, type: :boolean
indexes :visibility_level, type: :integer indexes :visibility_level, type: :integer
indexes :last_activity_at, type: :date indexes :last_activity_at, type: :date
...@@ -40,6 +41,7 @@ module Elastic ...@@ -40,6 +41,7 @@ module Elastic
:description, :description,
:namespace_id, :namespace_id,
:created_at, :created_at,
:updated_at,
:archived, :archived,
:visibility_level, :visibility_level,
:last_activity_at, :last_activity_at,
......
...@@ -5,6 +5,8 @@ module Elastic ...@@ -5,6 +5,8 @@ module Elastic
included do included do
include Elasticsearch::Git::Repository include Elasticsearch::Git::Repository
index_name [Rails.application.class.parent_name.downcase, Rails.env].join('-')
def repository_id def repository_id
project.id project.id
end end
...@@ -18,8 +20,6 @@ module Elastic ...@@ -18,8 +20,6 @@ module Elastic
end end
def self.import def self.import
Repository.__elasticsearch__.create_index!
Project.find_each do |project| Project.find_each do |project|
if project.repository.exists? && !project.repository.empty? if project.repository.exists? && !project.repository.empty?
project.repository.index_commits project.repository.index_commits
......
...@@ -21,8 +21,6 @@ module Elastic ...@@ -21,8 +21,6 @@ module Elastic
indexes :project_id, type: :integer indexes :project_id, type: :integer
indexes :author_id, type: :integer indexes :author_id, type: :integer
indexes :visibility_level, type: :integer indexes :visibility_level, type: :integer
indexes :updated_at_sort, type: :date, index: :not_analyzed
end end
def as_indexed_json(options = {}) def as_indexed_json(options = {})
...@@ -62,7 +60,7 @@ module Elastic ...@@ -62,7 +60,7 @@ module Elastic
query_hash = filter(query_hash, options[:user]) query_hash = filter(query_hash, options[:user])
query_hash[:sort] = [ query_hash[:sort] = [
{ updated_at_sort: { order: :desc, mode: :min } }, { updated_at: { order: :desc } },
:_score :_score
] ]
......
...@@ -5,6 +5,8 @@ module Elastic ...@@ -5,6 +5,8 @@ module Elastic
included do included do
include Elasticsearch::Git::Repository include Elasticsearch::Git::Repository
index_name [Rails.application.class.parent_name.downcase, Rails.env].join('-')
def repository_id def repository_id
"wiki_#{project.id}" "wiki_#{project.id}"
end end
...@@ -18,8 +20,6 @@ module Elastic ...@@ -18,8 +20,6 @@ module Elastic
end end
def self.import def self.import
ProjectWiki.__elasticsearch__.create_index!
Project.where(wiki_enabled: true).find_each do |project| Project.where(wiki_enabled: true).find_each do |project|
unless project.wiki.empty? unless project.wiki.empty?
project.wiki.index_blobs project.wiki.index_blobs
......
class PersonalSnippet < Snippet class PersonalSnippet < Snippet
# Elastic search configuration (it does not support STI) # Elastic search configuration (it does not support STI)
document_type 'snippet' document_type 'snippet'
index_name [Rails.application.class.parent_name.downcase, 'snippet', Rails.env].join('-') index_name [Rails.application.class.parent_name.downcase, Rails.env].join('-')
include Elastic::SnippetsSearch include Elastic::SnippetsSearch
end end
class ProjectSnippet < Snippet class ProjectSnippet < Snippet
# Elastic search configuration (it does not support STI) # Elastic search configuration (it does not support STI)
document_type 'snippet' document_type 'snippet'
index_name [Rails.application.class.parent_name.downcase, 'snippet', Rails.env].join('-') index_name [Rails.application.class.parent_name.downcase, Rails.env].join('-')
include Elastic::SnippetsSearch include Elastic::SnippetsSearch
belongs_to :project belongs_to :project
......
...@@ -18,9 +18,14 @@ ...@@ -18,9 +18,14 @@
.error-alert .error-alert
.help-block .help-block
To link to a (new) page, simply type = succeed '.' do
%code [Link Title](page-slug) To link to a (new) page, simply type
\. %code [Link Title](page-slug)
= succeed '.' do
More examples are in the
= link_to 'documentation', help_page_path("user/project/markdown", anchor: "wiki-specific-markdown")
.form-group .form-group
= f.label :commit_message, class: 'control-label' = f.label :commit_message, class: 'control-label'
.col-sm-10= f.text_field :message, class: 'form-control', rows: 18 .col-sm-10= f.text_field :message, class: 'form-control', rows: 18
......
...@@ -20,7 +20,7 @@ ELASTIC_PORT = elastic_connection_info['port'] ...@@ -20,7 +20,7 @@ ELASTIC_PORT = elastic_connection_info['port']
class Repository class Repository
include Elasticsearch::Git::Repository include Elasticsearch::Git::Repository
index_name ['repository', 'index', RAILS_ENV].compact.join('-') index_name ['gitlab', RAILS_ENV].compact.join('-')
self.__elasticsearch__.client = Elasticsearch::Client.new( self.__elasticsearch__.client = Elasticsearch::Client.new(
host: ELASTIC_HOST, host: ELASTIC_HOST,
...@@ -40,8 +40,6 @@ class Repository ...@@ -40,8 +40,6 @@ class Repository
end end
end end
Repository.__elasticsearch__.create_index!
repo = Repository.new repo = Repository.new
params = { from_rev: FROM_SHA, to_rev: TO_SHA }.compact params = { from_rev: FROM_SHA, to_rev: TO_SHA }.compact
...@@ -52,4 +50,4 @@ puts "Done" ...@@ -52,4 +50,4 @@ puts "Done"
print "Indexing blobs..." print "Indexing blobs..."
repo.index_blobs(params) repo.index_blobs(params)
puts "Done" puts "Done"
\ No newline at end of file
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
- [GitLab Basics](gitlab-basics/README.md) Find step by step how to start working on your commandline and on GitLab. - [GitLab Basics](gitlab-basics/README.md) Find step by step how to start working on your commandline and on GitLab.
- [Importing to GitLab](workflow/importing/README.md). - [Importing to GitLab](workflow/importing/README.md).
- [Importing and exporting projects between instances](user/project/settings/import_export.md). - [Importing and exporting projects between instances](user/project/settings/import_export.md).
- [Markdown](markdown/markdown.md) GitLab's advanced formatting system. - [Markdown](user/project/markdown.md) GitLab's advanced formatting system.
- [Migrating from SVN](workflow/importing/migrating_from_svn.md) Convert a SVN repository to Git and GitLab. - [Migrating from SVN](workflow/importing/migrating_from_svn.md) Convert a SVN repository to Git and GitLab.
- [Permissions](user/permissions.md) Learn what each role in a project (external/guest/reporter/developer/master/owner) can do. - [Permissions](user/permissions.md) Learn what each role in a project (external/guest/reporter/developer/master/owner) can do.
- [Profile Settings](profile/README.md) - [Profile Settings](profile/README.md)
......
...@@ -64,10 +64,10 @@ Configure Elasticsearch's host and port in **Admin > Settings**. Then create emp ...@@ -64,10 +64,10 @@ Configure Elasticsearch's host and port in **Admin > Settings**. Then create emp
``` ```
# Omnibus installations # Omnibus installations
sudo gitlab-rake gitlab:elastic:create_empty_indexes sudo gitlab-rake gitlab:elastic:create_empty_index
# Installations from source # Installations from source
bundle exec rake gitlab:elastic:create_empty_indexes bundle exec rake gitlab:elastic:create_empty_index
``` ```
...@@ -216,10 +216,10 @@ To minimize downtime of the search feature we recommend the following: ...@@ -216,10 +216,10 @@ To minimize downtime of the search feature we recommend the following:
``` ```
# Omnibus installations # Omnibus installations
sudo gitlab-rake gitlab:elastic:create_empty_indexes sudo gitlab-rake gitlab:elastic:create_empty_index
# Installations from source # Installations from source
bundle exec rake gitlab:elastic:create_empty_indexes bundle exec rake gitlab:elastic:create_empty_index
``` ```
1. Index all repositories using the `gitlab:elastic:index_repositories` Rake 1. Index all repositories using the `gitlab:elastic:index_repositories` Rake
...@@ -227,8 +227,8 @@ To minimize downtime of the search feature we recommend the following: ...@@ -227,8 +227,8 @@ To minimize downtime of the search feature we recommend the following:
1. Enable Elasticsearch indexing. 1. Enable Elasticsearch indexing.
1. Run indexers for database (with the `UPDATE_INDEX=1` parameter), wikis, and 1. Run indexers for database, wikis, and
repositories. By running the repository indexer twice you will be sure that repositories (with the `UPDATE_INDEX=1` parameter). By running the repository indexer twice you will be sure that
everything is indexed because some commits could be pushed while you everything is indexed because some commits could be pushed while you
performed the initial indexing. The repository indexer will skip performed the initial indexing. The repository indexer will skip
repositories and commits that are already indexed, so it will be much repositories and commits that are already indexed, so it will be much
......
# From Community Edition 8.11 to Enterprise Edition 8.11
This guide assumes you have a correctly configured and tested installation of
GitLab Community Edition 8.11. If you run into any trouble or if you have any
questions please contact us at [support@gitlab.com].
### 0. Backup
Make a backup just in case something goes wrong:
```bash
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
```
For installations using MySQL, this may require granting "LOCK TABLES"
privileges to the GitLab user on the database version.
### 1. Stop server
sudo service gitlab stop
### 2. Get the EE code
```bash
cd /home/git/gitlab
sudo -u git -H git remote add -f ee https://gitlab.com/gitlab-org/gitlab-ee.git
sudo -u git -H git checkout 8-11-stable-ee
```
### 3. Install libs, migrations, etc.
```bash
cd /home/git/gitlab
# MySQL installations (note: the line below states '--without postgres')
sudo -u git -H bundle install --without postgres development test --deployment
# PostgreSQL installations (note: the line below states '--without mysql')
sudo -u git -H bundle install --without mysql development test --deployment
# Run database migrations
sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production
# Clean up assets and cache
sudo -u git -H bundle exec rake assets:clean assets:precompile cache:clear RAILS_ENV=production
```
### 4. Start application
sudo service gitlab start
sudo service nginx restart
### 5. Check application status
Check if GitLab and its environment are configured correctly:
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
To make sure you didn't miss anything run a more thorough check with:
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
If all items are green, then congratulations upgrade complete!
## Things went south? Revert to previous version (Community Edition 8.11)
### 1. Revert the code to the previous version
```bash
cd /home/git/gitlab
sudo -u git -H git checkout 8-11-stable
```
### 2. Restore from the backup
```bash
cd /home/git/gitlab
sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=production
```
[support@gitlab.com]: mailto:support@gitlab.com
...@@ -28,6 +28,13 @@ ...@@ -28,6 +28,13 @@
* [Line Breaks](#line-breaks) * [Line Breaks](#line-breaks)
* [Tables](#tables) * [Tables](#tables)
**[Wiki-Specific Markdown](#wiki-specific-markdown)**
* [Wiki - Direct page link](#wiki-direct-page-link)
* [Wiki - Direct file link](#wiki-direct-file-link)
* [Wiki - Hierarchical link](#wiki-hierarchical-link)
* [Wiki - Root link](#wiki-root-link)
**[References](#references)** **[References](#references)**
## GitLab Flavored Markdown (GFM) ## GitLab Flavored Markdown (GFM)
...@@ -331,11 +338,11 @@ The valid video extensions are `.mp4`, `.m4v`, `.mov`, `.webm`, and `.ogv`. ...@@ -331,11 +338,11 @@ The valid video extensions are `.mp4`, `.m4v`, `.mov`, `.webm`, and `.ogv`.
Here's a sample video: Here's a sample video:
![Sample Video](img/video.mp4) ![Sample Video](img/markdown_video.mp4)
Here's a sample video: Here's a sample video:
![Sample Video](img/video.mp4) ![Sample Video](img/markdown_video.mp4)
# Standard Markdown # Standard Markdown
...@@ -533,24 +540,24 @@ will point the link to `wikis/style` when the link is inside of a wiki markdown ...@@ -533,24 +540,24 @@ will point the link to `wikis/style` when the link is inside of a wiki markdown
Here's our logo (hover to see the title text): Here's our logo (hover to see the title text):
Inline-style: Inline-style:
![alt text](img/logo.png) ![alt text](img/markdown_logo.png)
Reference-style: Reference-style:
![alt text1][logo] ![alt text1][logo]
[logo]: img/logo.png [logo]: img/markdown_logo.png
Here's our logo: Here's our logo:
Inline-style: Inline-style:
![alt text](img/logo.png) ![alt text](img/markdown_logo.png)
Reference-style: Reference-style:
![alt text][logo] ![alt text][logo]
[logo]: img/logo.png [logo]: img/markdown_logo.png
## Blockquotes ## Blockquotes
...@@ -692,6 +699,81 @@ By including colons in the header row, you can align the text within that column ...@@ -692,6 +699,81 @@ By including colons in the header row, you can align the text within that column
| Cell 1 | Cell 2 | Cell 3 | Cell 4 | Cell 5 | Cell 6 | | Cell 1 | Cell 2 | Cell 3 | Cell 4 | Cell 5 | Cell 6 |
| Cell 7 | Cell 8 | Cell 9 | Cell 10 | Cell 11 | Cell 12 | | Cell 7 | Cell 8 | Cell 9 | Cell 10 | Cell 11 | Cell 12 |
## Wiki-specific Markdown
The following examples show how links inside wikis behave.
### Wiki - Direct page link
A link which just includes the slug for a page will point to that page,
_at the base level of the wiki_.
This snippet would link to a `documentation` page at the root of your wiki:
```markdown
[Link to Documentation](documentation)
```
### Wiki - Direct file link
Links with a file extension point to that file, _relative to the current page_.
If this snippet was placed on a page at `<your_wiki>/documentation/related`,
it would link to `<your_wiki>/documentation/file.md`:
```markdown
[Link to File](file.md)
```
### Wiki - Hierarchical link
A link can be constructed relative to the current wiki page using `./<page>`,
`../<page>`, etc.
- If this snippet was placed on a page at `<your_wiki>/documentation/main`,
it would link to `<your_wiki>/documentation/related`:
```markdown
[Link to Related Page](./related)
```
- If this snippet was placed on a page at `<your_wiki>/documentation/related/content`,
it would link to `<your_wiki>/documentation/main`:
```markdown
[Link to Related Page](../main)
```
- If this snippet was placed on a page at `<your_wiki>/documentation/main`,
it would link to `<your_wiki>/documentation/related.md`:
```markdown
[Link to Related Page](./related.md)
```
- If this snippet was placed on a page at `<your_wiki>/documentation/related/content`,
it would link to `<your_wiki>/documentation/main.md`:
```markdown
[Link to Related Page](../main.md)
```
### Wiki - Root link
A link starting with a `/` is relative to the wiki root.
- This snippet links to `<wiki_root>/documentation`:
```markdown
[Link to Related Page](/documentation)
```
- This snippet links to `<wiki_root>/miscellaneous.md`:
```markdown
[Link to Related Page](/miscellaneous.md)
```
## References ## References
- This document leveraged heavily from the [Markdown-Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet). - This document leveraged heavily from the [Markdown-Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
......
...@@ -8,15 +8,11 @@ class Spinach::Features::GlobalSearch < Spinach::FeatureSteps ...@@ -8,15 +8,11 @@ class Spinach::Features::GlobalSearch < Spinach::FeatureSteps
include StubConfiguration include StubConfiguration
before do before do
[::Project, Issue, MergeRequest, Milestone].each do |model| Gitlab::Elastic::Helper.create_empty_index
model.__elasticsearch__.create_index!
end
end end
after do after do
[::Project, Issue, MergeRequest, Milestone].each do |model| Gitlab::Elastic::Helper.delete_index
model.__elasticsearch__.delete_index!
end
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
......
...@@ -6,15 +6,11 @@ class Spinach::Features::ProjectSearch < Spinach::FeatureSteps ...@@ -6,15 +6,11 @@ class Spinach::Features::ProjectSearch < Spinach::FeatureSteps
include StubConfiguration include StubConfiguration
before do before do
[::Project, Repository, Note, MergeRequest, Milestone, ::ProjectWiki, Issue].each do |model| Gitlab::Elastic::Helper.create_empty_index
model.__elasticsearch__.create_index!
end
end end
after do after do
[::Project, Repository, Note, MergeRequest, Milestone, ::ProjectWiki, Issue].each do |model| Gitlab::Elastic::Helper.delete_index
model.__elasticsearch__.delete_index!
end
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
......
...@@ -6,23 +6,23 @@ class Spinach::Features::SnippetsSearch < Spinach::FeatureSteps ...@@ -6,23 +6,23 @@ class Spinach::Features::SnippetsSearch < Spinach::FeatureSteps
include StubConfiguration include StubConfiguration
before do before do
Snippet.__elasticsearch__.create_index! Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Snippet.__elasticsearch__.delete_index! Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
step 'there is a snippet "index" with "php rocks" string' do step 'there is a snippet "index" with "php rocks" string' do
create :personal_snippet, :public, content: "php rocks", title: "index" create :personal_snippet, :public, content: "php rocks", title: "index"
Snippet.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
end end
step 'there is a snippet "php" with "benefits" string' do step 'there is a snippet "php" with "benefits" string' do
create :personal_snippet, :public, content: "benefits", title: "php" create :personal_snippet, :public, content: "benefits", title: "php"
Snippet.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
end end
step 'I search "php"' do step 'I search "php"' do
......
module Gitlab
module Elastic
class Helper
def self.create_empty_index
index_name = Project.index_name
settings = {}
mappings = {}
[
Project,
Issue,
MergeRequest,
Snippet,
Note,
Milestone,
ProjectWiki,
Repository
].each do |klass|
settings.deep_merge!(klass.settings.to_hash)
mappings.merge!(klass.mappings.to_hash)
end
client = Project.__elasticsearch__.client
if client.indices.exists? index: index_name
client.indices.delete index: index_name
end
client.indices.create index: index_name,
body: {
settings: settings.to_hash,
mappings: mappings.to_hash }
end
def self.delete_index
Project.__elasticsearch__.delete_index!
end
def self.refresh_index
Project.__elasticsearch__.refresh_index!
end
end
end
end
namespace :gitlab do namespace :gitlab do
namespace :elastic do namespace :elastic do
desc "GitLab | Update Elasticsearch indexes" desc "GitLab | Elasticsearch | Index eveything at once"
task :index do task :index do
Rake::Task["gitlab:elastic:create_empty_index"].invoke
Rake::Task["gitlab:elastic:clear_index_status"].invoke
Rake::Task["gitlab:elastic:index_repositories"].invoke Rake::Task["gitlab:elastic:index_repositories"].invoke
Rake::Task["gitlab:elastic:index_wikis"].invoke Rake::Task["gitlab:elastic:index_wikis"].invoke
Rake::Task["gitlab:elastic:index_database"].invoke Rake::Task["gitlab:elastic:index_database"].invoke
end end
desc "GitLab | Update Elasticsearch indexes for project repositories" desc "GitLab | Elasticsearch | Index project repositories"
task index_repositories: :environment do task index_repositories: :environment do
Repository.__elasticsearch__.create_index!
projects = if ENV['UPDATE_INDEX'] projects = if ENV['UPDATE_INDEX']
Project Project
else else
...@@ -56,10 +56,8 @@ namespace :gitlab do ...@@ -56,10 +56,8 @@ namespace :gitlab do
end end
end end
desc "GitLab | Update Elasticsearch indexes for wiki repositories" desc "GitLab | Elasticsearch | Index wiki repositories"
task index_wikis: :environment do task index_wikis: :environment do
ProjectWiki.__elasticsearch__.create_index!
projects = apply_project_filters(Project.where(wiki_enabled: true)) projects = apply_project_filters(Project.where(wiki_enabled: true))
projects.find_each do |project| projects.find_each do |project|
...@@ -75,11 +73,9 @@ namespace :gitlab do ...@@ -75,11 +73,9 @@ namespace :gitlab do
end end
end end
desc "GitLab | Update Elasticsearch indexes for all database objects" desc "GitLab | Elasticsearch | Index all database objects"
task index_database: :environment do task index_database: :environment do
[Project, Issue, MergeRequest, Snippet, Note, Milestone].each do |klass| [Project, Issue, MergeRequest, Snippet, Note, Milestone].each do |klass|
klass.__elasticsearch__.create_index!
print "Indexing #{klass} records... " print "Indexing #{klass} records... "
if klass == Note if klass == Note
...@@ -92,72 +88,28 @@ namespace :gitlab do ...@@ -92,72 +88,28 @@ namespace :gitlab do
end end
end end
desc "GitLab | Recreate Elasticsearch indexes for particular model" desc "GitLab | Elasticsearch | Create empty index"
task reindex_model: :environment do task create_empty_index: :environment do
model_name = ENV['MODEL'] Gitlab::Elastic::Helper.create_empty_index
puts "Index created".color(:green)
unless %w(Project Issue MergeRequest Snippet Note Milestone).include?(model_name)
raise "Please pass MODEL variable"
end
klass = model_name.constantize
klass.__elasticsearch__.create_index! force: true
print "Reindexing #{klass} records... "
if klass == Note
Note.searchable.import
else
klass.import
end
puts "done".color(:green)
end
desc "GitLab | Create empty Elasticsearch indexes"
task create_empty_indexes: :environment do
[
Project,
Issue,
MergeRequest,
Snippet,
Note,
Milestone,
ProjectWiki,
Repository
].each do |klass|
print "Creating index for #{klass}... "
klass.__elasticsearch__.create_index!
puts "done".color(:green)
end
end end
desc "GitLab | Clear Elasticsearch indexing status" desc "GitLab | Elasticsearch | Clear indexing status"
task clear_index_status: :environment do task clear_index_status: :environment do
IndexStatus.destroy_all IndexStatus.destroy_all
puts "Done".color(:green) puts "Index status has been reset".color(:green)
end end
desc "GitLab | Delete Elasticsearch indexes" desc "GitLab | Elasticsearch | Delete index"
task delete_indexes: :environment do task delete_index: :environment do
[ Gitlab::Elastic::Helper.delete_index
Project, puts "Index deleted".color(:green)
Issue, end
MergeRequest,
Snippet,
Note,
Milestone,
ProjectWiki,
Repository
].each do |klass|
print "Delete index for #{klass}... "
klass.__elasticsearch__.delete_index!
puts "done".color(:green) desc "GitLab | Elasticsearch | Recreate index"
end task recreate_index: :environment do
Gitlab::Elastic::Helper.create_empty_index
puts "Index recreated".color(:green)
end end
def apply_project_filters(projects) def apply_project_filters(projects)
......
...@@ -6,30 +6,22 @@ feature 'Global elastic search', feature: true do ...@@ -6,30 +6,22 @@ feature 'Global elastic search', feature: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index
project.team << [user, :master] project.team << [user, :master]
login_with(user) login_with(user)
end end
after do after do
Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
describe 'I search through the issues and I see pagination' do describe 'I search through the issues and I see pagination' do
before do before do
[::Project, Issue, MergeRequest, Milestone].each do |model|
model.__elasticsearch__.create_index!
end
create_list(:issue, 21, project: project, title: 'initial') create_list(:issue, 21, project: project, title: 'initial')
Issue.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
end
after do
[::Project, Issue, MergeRequest, Milestone].each do |model|
model.__elasticsearch__.delete_index!
end
end end
it "has a pagination" do it "has a pagination" do
......
...@@ -7,14 +7,12 @@ describe Gitlab::Elastic::ProjectSearchResults, lib: true do ...@@ -7,14 +7,12 @@ describe Gitlab::Elastic::ProjectSearchResults, lib: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Project.__elasticsearch__.create_index! Gitlab::Elastic::Helper.create_empty_index
Issue.__elasticsearch__.create_index!
end end
after do after do
Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
Project.__elasticsearch__.delete_index!
Issue.__elasticsearch__.delete_index!
end end
describe 'initialize with empty ref' do describe 'initialize with empty ref' do
...@@ -53,7 +51,7 @@ describe Gitlab::Elastic::ProjectSearchResults, lib: true do ...@@ -53,7 +51,7 @@ describe Gitlab::Elastic::ProjectSearchResults, lib: true do
project1.wiki.create_page("index_page", " term") project1.wiki.create_page("index_page", " term")
project1.wiki.index_blobs project1.wiki.index_blobs
Project.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
result = Gitlab::Elastic::ProjectSearchResults.new(user, project.id, "term") result = Gitlab::Elastic::ProjectSearchResults.new(user, project.id, "term")
expect(result.notes_count).to eq(1) expect(result.notes_count).to eq(1)
...@@ -77,7 +75,7 @@ describe Gitlab::Elastic::ProjectSearchResults, lib: true do ...@@ -77,7 +75,7 @@ describe Gitlab::Elastic::ProjectSearchResults, lib: true do
let!(:security_issue_2) { create(:issue, :confidential, title: 'Security issue 2', project: project, assignee: assignee) } let!(:security_issue_2) { create(:issue, :confidential, title: 'Security issue 2', project: project, assignee: assignee) }
before do before do
Issue.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
end end
it 'should not list project confidential issues for non project members' do it 'should not list project confidential issues for non project members' do
......
...@@ -3,9 +3,11 @@ require 'spec_helper' ...@@ -3,9 +3,11 @@ require 'spec_helper'
describe Gitlab::Elastic::SearchResults, lib: true do describe Gitlab::Elastic::SearchResults, lib: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
...@@ -16,8 +18,6 @@ describe Gitlab::Elastic::SearchResults, lib: true do ...@@ -16,8 +18,6 @@ describe Gitlab::Elastic::SearchResults, lib: true do
describe 'issues' do describe 'issues' do
before do before do
Issue.__elasticsearch__.create_index!
@issue_1 = create( @issue_1 = create(
:issue, :issue,
project: project_1, project: project_1,
...@@ -38,11 +38,7 @@ describe Gitlab::Elastic::SearchResults, lib: true do ...@@ -38,11 +38,7 @@ describe Gitlab::Elastic::SearchResults, lib: true do
iid: 2 iid: 2
) )
Issue.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
end
after do
Issue.__elasticsearch__.delete_index!
end end
it 'should list issues that title or description contain the query' do it 'should list issues that title or description contain the query' do
...@@ -91,8 +87,6 @@ describe Gitlab::Elastic::SearchResults, lib: true do ...@@ -91,8 +87,6 @@ describe Gitlab::Elastic::SearchResults, lib: true do
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
before do before do
Issue.__elasticsearch__.create_index!
@issue = create(:issue, project: project_1, title: 'Issue 1', iid: 1) @issue = create(:issue, project: project_1, title: 'Issue 1', iid: 1)
@security_issue_1 = create(:issue, :confidential, project: project_1, title: 'Security issue 1', author: author, iid: 2) @security_issue_1 = create(:issue, :confidential, project: project_1, title: 'Security issue 1', author: author, iid: 2)
@security_issue_2 = create(:issue, :confidential, title: 'Security issue 2', project: project_1, assignee: assignee, iid: 3) @security_issue_2 = create(:issue, :confidential, title: 'Security issue 2', project: project_1, assignee: assignee, iid: 3)
...@@ -100,7 +94,7 @@ describe Gitlab::Elastic::SearchResults, lib: true do ...@@ -100,7 +94,7 @@ describe Gitlab::Elastic::SearchResults, lib: true do
@security_issue_4 = create(:issue, :confidential, project: project_3, title: 'Security issue 4', assignee: assignee, iid: 1) @security_issue_4 = create(:issue, :confidential, project: project_3, title: 'Security issue 4', assignee: assignee, iid: 1)
@security_issue_5 = create(:issue, :confidential, project: project_4, title: 'Security issue 5', iid: 1) @security_issue_5 = create(:issue, :confidential, project: project_4, title: 'Security issue 5', iid: 1)
Issue.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
end end
context 'search by term' do context 'search by term' do
...@@ -276,8 +270,6 @@ describe Gitlab::Elastic::SearchResults, lib: true do ...@@ -276,8 +270,6 @@ describe Gitlab::Elastic::SearchResults, lib: true do
describe 'merge requests' do describe 'merge requests' do
before do before do
MergeRequest.__elasticsearch__.create_index!
@merge_request_1 = create( @merge_request_1 = create(
:merge_request, :merge_request,
source_project: project_1, source_project: project_1,
...@@ -302,11 +294,7 @@ describe Gitlab::Elastic::SearchResults, lib: true do ...@@ -302,11 +294,7 @@ describe Gitlab::Elastic::SearchResults, lib: true do
iid: 2 iid: 2
) )
MergeRequest.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
end
after do
MergeRequest.__elasticsearch__.delete_index!
end end
it 'should list merge requests that title or description contain the query' do it 'should list merge requests that title or description contain the query' do
...@@ -345,18 +333,6 @@ describe Gitlab::Elastic::SearchResults, lib: true do ...@@ -345,18 +333,6 @@ describe Gitlab::Elastic::SearchResults, lib: true do
end end
describe 'project scoping' do describe 'project scoping' do
before do
[Project, MergeRequest, Issue, Milestone].each do |model|
model.__elasticsearch__.create_index!
end
end
after do
[Project, MergeRequest, Issue, Milestone].each do |model|
model.__elasticsearch__.delete_index!
end
end
it "returns items for project" do it "returns items for project" do
project = create :project, name: "term" project = create :project, name: "term"
...@@ -380,9 +356,7 @@ describe Gitlab::Elastic::SearchResults, lib: true do ...@@ -380,9 +356,7 @@ describe Gitlab::Elastic::SearchResults, lib: true do
# The Milestone you have no access to # The Milestone you have no access to
create :milestone, title: 'bla-bla term' create :milestone, title: 'bla-bla term'
[Project, MergeRequest, Issue, Milestone].each do |model| Gitlab::Elastic::Helper.refresh_index
model.__elasticsearch__.refresh_index!
end
result = Gitlab::Elastic::SearchResults.new(user, [project.id], 'term') result = Gitlab::Elastic::SearchResults.new(user, [project.id], 'term')
......
...@@ -3,11 +3,11 @@ require 'spec_helper' ...@@ -3,11 +3,11 @@ require 'spec_helper'
describe Issue, elastic: true do describe Issue, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
described_class.__elasticsearch__.create_index! Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
described_class.__elasticsearch__.delete_index! Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
...@@ -21,7 +21,7 @@ describe Issue, elastic: true do ...@@ -21,7 +21,7 @@ describe Issue, elastic: true do
# The issue I have no access to # The issue I have no access to
create :issue, title: 'bla-bla term' create :issue, title: 'bla-bla term'
described_class.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
options = { project_ids: [project.id] } options = { project_ids: [project.id] }
...@@ -36,10 +36,6 @@ describe Issue, elastic: true do ...@@ -36,10 +36,6 @@ describe Issue, elastic: true do
'updated_at', 'state', 'project_id', 'author_id', 'updated_at', 'state', 'project_id', 'author_id',
'assignee_id', 'confidential') 'assignee_id', 'confidential')
expected_hash['project'] = { "id" => project.id }
expected_hash['author'] = { "id" => issue.author_id }
expected_hash['updated_at_sort'] = issue.updated_at
expect(issue.as_indexed_json).to eq(expected_hash) expect(issue.as_indexed_json).to eq(expected_hash)
end end
end end
...@@ -3,11 +3,11 @@ require 'spec_helper' ...@@ -3,11 +3,11 @@ require 'spec_helper'
describe MergeRequest, elastic: true do describe MergeRequest, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
described_class.__elasticsearch__.create_index! Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
described_class.__elasticsearch__.delete_index! Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
...@@ -21,7 +21,7 @@ describe MergeRequest, elastic: true do ...@@ -21,7 +21,7 @@ describe MergeRequest, elastic: true do
# The merge request you have no access to # The merge request you have no access to
create :merge_request, title: 'also with term' create :merge_request, title: 'also with term'
described_class.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
options = { project_ids: [project.id] } options = { project_ids: [project.id] }
...@@ -47,8 +47,6 @@ describe MergeRequest, elastic: true do ...@@ -47,8 +47,6 @@ describe MergeRequest, elastic: true do
'author_id' 'author_id'
) )
expected_hash['updated_at_sort'] = merge_request.updated_at
expect(merge_request.as_indexed_json).to eq(expected_hash) expect(merge_request.as_indexed_json).to eq(expected_hash)
end end
end end
...@@ -3,11 +3,11 @@ require 'spec_helper' ...@@ -3,11 +3,11 @@ require 'spec_helper'
describe Milestone, elastic: true do describe Milestone, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
described_class.__elasticsearch__.create_index! Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
described_class.__elasticsearch__.delete_index! Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
...@@ -21,7 +21,7 @@ describe Milestone, elastic: true do ...@@ -21,7 +21,7 @@ describe Milestone, elastic: true do
# The milestone you have no access to # The milestone you have no access to
create :milestone, title: 'bla-bla term' create :milestone, title: 'bla-bla term'
described_class.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
options = { project_ids: [project.id] } options = { project_ids: [project.id] }
...@@ -36,11 +36,10 @@ describe Milestone, elastic: true do ...@@ -36,11 +36,10 @@ describe Milestone, elastic: true do
'title', 'title',
'description', 'description',
'project_id', 'project_id',
'created_at' 'created_at',
'updated_at'
) )
expected_hash[:updated_at_sort] = milestone.updated_at
expect(milestone.as_indexed_json).to eq(expected_hash) expect(milestone.as_indexed_json).to eq(expected_hash)
end end
end end
...@@ -3,11 +3,11 @@ require 'spec_helper' ...@@ -3,11 +3,11 @@ require 'spec_helper'
describe Note, elastic: true do describe Note, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
described_class.__elasticsearch__.create_index! Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
described_class.__elasticsearch__.delete_index! Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
...@@ -20,7 +20,7 @@ describe Note, elastic: true do ...@@ -20,7 +20,7 @@ describe Note, elastic: true do
# The note in the project you have no access to # The note in the project you have no access to
create :note, note: 'bla-bla term' create :note, note: 'bla-bla term'
described_class.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
options = { project_ids: [issue.project.id] } options = { project_ids: [issue.project.id] }
...@@ -35,8 +35,9 @@ describe Note, elastic: true do ...@@ -35,8 +35,9 @@ describe Note, elastic: true do
'note', 'note',
'project_id', 'project_id',
'created_at', 'created_at',
'issue', 'updated_at',
'updated_at_sort' 'issue'
] ]
expect(note.as_indexed_json.keys).to eq(expected_hash_keys) expect(note.as_indexed_json.keys).to eq(expected_hash_keys)
...@@ -58,7 +59,7 @@ describe Note, elastic: true do ...@@ -58,7 +59,7 @@ describe Note, elastic: true do
create :note, note: 'bla-bla term', project: issue.project, noteable: issue create :note, note: 'bla-bla term', project: issue.project, noteable: issue
create :note, project: issue.project, noteable: issue create :note, project: issue.project, noteable: issue
Note.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
options = { project_ids: [issue.project.id] } options = { project_ids: [issue.project.id] }
...@@ -72,7 +73,7 @@ describe Note, elastic: true do ...@@ -72,7 +73,7 @@ describe Note, elastic: true do
create :note, note: 'bla-bla term', project: issue.project, noteable: issue create :note, note: 'bla-bla term', project: issue.project, noteable: issue
create :note, project: issue.project, noteable: issue create :note, project: issue.project, noteable: issue
Note.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
options = { project_ids: [issue.project.id], current_user: user } options = { project_ids: [issue.project.id], current_user: user }
...@@ -89,7 +90,7 @@ describe Note, elastic: true do ...@@ -89,7 +90,7 @@ describe Note, elastic: true do
create :note, note: 'bla-bla term', project: issue.project, noteable: issue create :note, note: 'bla-bla term', project: issue.project, noteable: issue
create :note, project: issue.project, noteable: issue create :note, project: issue.project, noteable: issue
Note.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
options = { project_ids: [issue.project.id], current_user: member } options = { project_ids: [issue.project.id], current_user: member }
...@@ -106,7 +107,7 @@ describe Note, elastic: true do ...@@ -106,7 +107,7 @@ describe Note, elastic: true do
create :note, note: 'bla-bla term', project: issue.project, noteable: issue create :note, note: 'bla-bla term', project: issue.project, noteable: issue
create :note, project: issue.project, noteable: issue create :note, project: issue.project, noteable: issue
Note.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
options = { project_ids: [issue.project.id], current_user: member } options = { project_ids: [issue.project.id], current_user: member }
......
...@@ -3,11 +3,11 @@ require 'spec_helper' ...@@ -3,11 +3,11 @@ require 'spec_helper'
describe Project, elastic: true do describe Project, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
described_class.__elasticsearch__.create_index! Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
described_class.__elasticsearch__.delete_index! Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
...@@ -18,7 +18,7 @@ describe Project, elastic: true do ...@@ -18,7 +18,7 @@ describe Project, elastic: true do
create :empty_project, path: 'someone_elses_project' create :empty_project, path: 'someone_elses_project'
project_ids = [project.id, project1.id, project2.id] project_ids = [project.id, project1.id, project2.id]
described_class.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
expect(described_class.elastic_search('test', options: { pids: project_ids }).total_count).to eq(1) expect(described_class.elastic_search('test', options: { pids: project_ids }).total_count).to eq(1)
expect(described_class.elastic_search('test1', options: { pids: project_ids }).total_count).to eq(1) expect(described_class.elastic_search('test1', options: { pids: project_ids }).total_count).to eq(1)
...@@ -36,6 +36,7 @@ describe Project, elastic: true do ...@@ -36,6 +36,7 @@ describe Project, elastic: true do
'namespace_id', 'namespace_id',
'created_at', 'created_at',
'archived', 'archived',
'updated_at',
'visibility_level', 'visibility_level',
'last_activity_at' 'last_activity_at'
) )
......
...@@ -3,11 +3,11 @@ require 'spec_helper' ...@@ -3,11 +3,11 @@ require 'spec_helper'
describe Repository, elastic: true do describe Repository, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
described_class.__elasticsearch__.create_index! Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
described_class.__elasticsearch__.delete_index! Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
...@@ -17,7 +17,7 @@ describe Repository, elastic: true do ...@@ -17,7 +17,7 @@ describe Repository, elastic: true do
project.repository.index_blobs project.repository.index_blobs
project.repository.index_commits project.repository.index_commits
described_class.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
expect(project.repository.search('def popen')[:blobs][:total_count]).to eq(1) expect(project.repository.search('def popen')[:blobs][:total_count]).to eq(1)
expect(project.repository.search('initial')[:commits][:total_count]).to eq(1) expect(project.repository.search('initial')[:commits][:total_count]).to eq(1)
......
...@@ -3,11 +3,11 @@ require 'spec_helper' ...@@ -3,11 +3,11 @@ require 'spec_helper'
describe Snippet, elastic: true do describe Snippet, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
described_class.__elasticsearch__.create_index! Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
described_class.__elasticsearch__.delete_index! Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
...@@ -24,7 +24,7 @@ describe Snippet, elastic: true do ...@@ -24,7 +24,7 @@ describe Snippet, elastic: true do
let!(:project_private_snippet) { create(:snippet, :private, project: project, content: 'password: XXX') } let!(:project_private_snippet) { create(:snippet, :private, project: project, content: 'password: XXX') }
before do before do
described_class.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
end end
it 'returns only public snippets when user is blank' do it 'returns only public snippets when user is blank' do
...@@ -78,7 +78,7 @@ describe Snippet, elastic: true do ...@@ -78,7 +78,7 @@ describe Snippet, elastic: true do
create(:snippet, :public, file_name: 'index.php') create(:snippet, :public, file_name: 'index.php')
create(:snippet) create(:snippet)
described_class.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
options = { user: user } options = { user: user }
......
...@@ -3,11 +3,11 @@ require 'spec_helper' ...@@ -3,11 +3,11 @@ require 'spec_helper'
describe ProjectWiki, elastic: true do describe ProjectWiki, elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
described_class.__elasticsearch__.create_index! Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
described_class.__elasticsearch__.delete_index! Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
...@@ -18,7 +18,7 @@ describe ProjectWiki, elastic: true do ...@@ -18,7 +18,7 @@ describe ProjectWiki, elastic: true do
project.wiki.index_blobs project.wiki.index_blobs
described_class.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
expect(project.wiki.search('bla', type: :blob)[:blobs][:total_count]).to eq(1) expect(project.wiki.search('bla', type: :blob)[:blobs][:total_count]).to eq(1)
end end
......
...@@ -973,11 +973,11 @@ describe Repository, models: true do ...@@ -973,11 +973,11 @@ describe Repository, models: true do
describe "Elastic search", elastic: true do describe "Elastic search", elastic: true do
before do before do
stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Repository.__elasticsearch__.create_index! Gitlab::Elastic::Helper.create_empty_index
end end
after do after do
Repository.__elasticsearch__.delete_index! Gitlab::Elastic::Helper.delete_index
stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false) stub_application_setting(elasticsearch_search: false, elasticsearch_indexing: false)
end end
...@@ -987,7 +987,7 @@ describe Repository, models: true do ...@@ -987,7 +987,7 @@ describe Repository, models: true do
project.repository.index_commits project.repository.index_commits
Repository.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
expect(project.repository.find_commits_by_message_with_elastic('initial').first).to be_a(Commit) expect(project.repository.find_commits_by_message_with_elastic('initial').first).to be_a(Commit)
expect(project.repository.find_commits_by_message_with_elastic('initial').count).to eq(1) expect(project.repository.find_commits_by_message_with_elastic('initial').count).to eq(1)
...@@ -1000,7 +1000,7 @@ describe Repository, models: true do ...@@ -1000,7 +1000,7 @@ describe Repository, models: true do
project.repository.index_blobs project.repository.index_blobs
Repository.__elasticsearch__.refresh_index! Gitlab::Elastic::Helper.refresh_index
result = project.repository.search( result = project.repository.search(
'def popen', 'def popen',
......
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