Commit c37e8a3b authored by Sean McGivern's avatar Sean McGivern

Merge branch '10393-ES-api-project_id-missing' into 'master'

[ES] Reinstate project_id missing from Blobs

Closes #10393

See merge request gitlab-org/gitlab-ee!10020
parents 19db5524 e90b6778
---
title: 'Elasticsearch API: Fix project_id showing as 0 for all blobs. A reindex will be required'
merge_request: 10020
author:
type: fixed
......@@ -96,6 +96,7 @@ module Elasticsearch
_id: "#{repository_id}_#{blob.path}",
routing: es_parent,
data: {
project_id: project_id,
blob: {
oid: blob.id,
rid: repository_id,
......@@ -236,6 +237,7 @@ module Elasticsearch
# Attention: It can be very very very huge hash
def as_indexed_json(options = {})
data = {}
data[:project_id] = project_id
data[:blobs] = index_blobs_array
data[:commits] = index_commits_array
data
......
......@@ -89,7 +89,7 @@ module Gitlab
extname = File.extname(filename)
basename = filename.sub(/#{extname}$/, '')
content = result["_source"]["blob"]["content"]
project_id = result["_parent"].to_i
project_id = result['_source']['project_id'].to_i
total_lines = content.lines.size
term =
......
......@@ -441,6 +441,8 @@ describe Gitlab::Elastic::SearchResults do
results = described_class.new(user, 'def', [project_1.id])
expect(results.blobs_count).to eq 7
result_project_ids = results.objects('blobs').map { |r| r.dig('_source', 'project_id') }
expect(result_project_ids.uniq).to eq([project_1.id])
results = described_class.new(user, 'def', [project_1.id, project_2.id])
......
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