How can I properly create an index in Elasticsearch using Ruby?


I have been trying to create an index using the ruby integrations of Elasticsearch. The code that I have as of now is as follows.

build_id = ENV['BUILD_NUM']
elastic_ip = ENV['ELASTIC_IP']

project_name = params[:project_name]
total_tests = params[:total_tests]
code_coverage = params[:code_coverage]
build_status = params[:build_status]

elasticBody = {totalTests: total_tests, codeCoverage: code_coverage, buildStatus: build_status}

client = host: elastic_ip, log: true
client.index index: project_name.downcase, id: build_id.to_i, body: elasticBody

This code is posting data to Elastic with no specific data type. So is there a way that I can specify the data type for the fields (total_tests = integer, codeCoverage = float, buildStatus = keyword) explicitly? My idea was to have the code for elasticBody as follows but I'm not sure if that would work.

elasticBody = {totalTests: total_tests.to_i, codeCoverage: code_coverage.to_f, buildStatus: build_status.to_s}

Thank you!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.