|
14 | 14 | # KIND, either express or implied. See the License for the |
15 | 15 | # specific language governing permissions and limitations |
16 | 16 | # under the License. |
17 | | -require_relative 'helpers_spec_helper' |
| 17 | +require_relative File.expand_path('../../spec_helper', __dir__) |
18 | 18 | require 'elasticsearch/helpers/bulk_helper' |
19 | 19 | require 'tempfile' |
20 | 20 |
|
|
23 | 23 | let(:index) { 'bulk_animals' } |
24 | 24 | let(:index_slice) { 'bulk_animals_slice' } |
25 | 25 | let(:params) { { refresh: 'wait_for' } } |
26 | | - let(:bulk_helper) { Elasticsearch::Helpers::BulkHelper.new(client, index, params) } |
| 26 | + let(:bulk_helper) { Elasticsearch::Helpers::BulkHelper.new(CLIENT, index, params) } |
27 | 27 | let(:docs) do |
28 | 28 | [ |
29 | | - { scientific_name: 'Lama guanicoe', name:'Guanaco' }, |
30 | | - { scientific_name: 'Tayassu pecari', name:'White-lipped peccary' }, |
31 | | - { scientific_name: 'Snycerus caffer', name:'Buffalo, african' }, |
32 | | - { scientific_name: 'Coluber constrictor', name:'Snake, racer' }, |
33 | | - { scientific_name: 'Thalasseus maximus', name:'Royal tern' }, |
34 | | - { scientific_name: 'Centrocercus urophasianus', name:'Hen, sage' }, |
35 | | - { scientific_name: 'Sitta canadensis', name:'Nuthatch, red-breasted' }, |
36 | | - { scientific_name: 'Aegypius tracheliotus', name:'Vulture, lappet-faced' }, |
37 | | - { scientific_name: 'Bucephala clangula', name:'Common goldeneye' }, |
38 | | - { scientific_name: 'Felis pardalis', name:'Ocelot' } |
| 29 | + { scientific_name: 'Lama guanicoe', name: 'Guanaco' }, |
| 30 | + { scientific_name: 'Tayassu pecari', name: 'White-lipped peccary' }, |
| 31 | + { scientific_name: 'Snycerus caffer', name: 'Buffalo, african' }, |
| 32 | + { scientific_name: 'Coluber constrictor', name: 'Snake, racer' }, |
| 33 | + { scientific_name: 'Thalasseus maximus', name: 'Royal tern' }, |
| 34 | + { scientific_name: 'Centrocercus urophasianus', name: 'Hen, sage' }, |
| 35 | + { scientific_name: 'Sitta canadensis', name: 'Nuthatch, red-breasted' }, |
| 36 | + { scientific_name: 'Aegypius tracheliotus', name: 'Vulture, lappet-faced' }, |
| 37 | + { scientific_name: 'Bucephala clangula', name: 'Common goldeneye' }, |
| 38 | + { scientific_name: 'Felis pardalis', name: 'Ocelot' } |
39 | 39 | ] |
40 | 40 | end |
41 | 41 |
|
42 | 42 | after do |
43 | | - client.indices.delete(index: index, ignore: 404) |
44 | | - client.indices.delete(index: index_slice, ignore: 404) |
| 43 | + CLIENT.indices.delete(index: index, ignore: 404) |
| 44 | + CLIENT.indices.delete(index: index_slice, ignore: 404) |
45 | 45 | end |
46 | 46 |
|
47 | 47 | it 'Ingests documents' do |
|
58 | 58 | ] |
59 | 59 | bulk_helper.ingest(docs) |
60 | 60 | # Get the ingested documents, add id and modify them to update them: |
61 | | - animals = client.search(index: index)['hits']['hits'] |
| 61 | + animals = CLIENT.search(index: index)['hits']['hits'] |
62 | 62 | # Add id to each doc |
63 | | - docs = animals.map { |animal| animal['_source'].merge({'id' => animal['_id'] }) } |
| 63 | + docs = animals.map { |animal| animal['_source'].merge({ 'id' => animal['_id'] }) } |
64 | 64 | docs.map { |doc| doc['scientific_name'].upcase! } |
65 | 65 | response = bulk_helper.update(docs) |
66 | 66 | expect(response.status).to eq(200) |
|
73 | 73 | response = bulk_helper.delete(ids) |
74 | 74 | expect(response.status).to eq 200 |
75 | 75 | expect(response['items'].map { |item| item['delete']['result'] }.uniq.first).to eq('deleted') |
76 | | - expect(client.count(index: index)['count']).to eq(0) |
| 76 | + expect(CLIENT.count(index: index)['count']).to eq(0) |
77 | 77 | end |
78 | 78 |
|
79 | 79 | it 'Ingests documents and yields response and docs' do |
80 | 80 | slice = 2 |
81 | | - bulk_helper = Elasticsearch::Helpers::BulkHelper.new(client, index_slice, params) |
82 | | - response = bulk_helper.ingest(docs, {slice: slice}) do |response, docs| |
| 81 | + bulk_helper = Elasticsearch::Helpers::BulkHelper.new(CLIENT, index_slice, params) |
| 82 | + bulk_helper.ingest(docs, { slice: slice }) do |response, docs| |
83 | 83 | expect(response).to be_an_instance_of Elasticsearch::API::Response |
84 | 84 | expect(docs.count).to eq slice |
85 | 85 | end |
86 | | - response = client.search(index: index_slice, size: 200) |
| 86 | + response = CLIENT.search(index: index_slice, size: 200) |
87 | 87 | expect(response['hits']['hits'].map { |a| a['_source'].transform_keys(&:to_sym) }).to eq docs |
88 | 88 | end |
89 | 89 |
|
|
0 commit comments