Skip to content

Instantly share code, notes, and snippets.

require 'es_spec_helper'
RSpec.describe 'ES search' do
before :all do
#Generate test data in db, using FactoryGirl for example
Integrations::EsSpecHelper.create_index(name: 'test_index', mapping: INDEX_DEFINITION)
#Use ETL to load data
SampleETL.populate_index('test_index')
dependencies:
post:
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.0.tar.gz
- tar -xvf elasticsearch-5.3.0.tar.gz
- elasticsearch-5.3.0/bin/elasticsearch: {background: true}
# Make sure that Elasticsearch is up before running tests:
- sleep 10 && wget --waitretry=5 --retry-connrefused -v http://127.0.0.1:9200/
Integrations::EsSpecHelper.remove_index(name: 'test_index')
ESClient.search(
index: 'test_index',
body: your_generated_query)
Integrations::EsSpecHelper.flush_index(name: 'test_index')
Integrations::EsSpecHelper.create_index(name: 'test_index', mapping: INDEX_DEFINITION)
INDEX_DEFINITION = {
mappings: {
sample: {
properties: {
message: {
type: 'text',
analyzer: 'standard'
}
}
}
module Integrations
module EsSpecHelper
def self.create_index(name:, mapping:)
ESClient.indices.create(index: name, body: mapping)
end
def self.remove_index(name:)
ESClient.indices.delete index: name
end
ESClient = Elasticsearch::Client.new(url: ‘http://localhost:9200')
@mikekr1
mikekr1 / crontab_example.txt
Created June 3, 2016 15:49
crontab example
0 14 15 * *