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

**URL:** <https://discuss.elastic.co/t/how-can-i-properly-create-an-index-in-elasticsearch-using-ruby/209620>\
**Category:** Elasticsearch\
**Created:** [November 27, 2019, 7:06am UTC](https://discuss.elastic.co/t/how-can-i-properly-create-an-index-in-elasticsearch-using-ruby/209620 "2019-11-27T07:06:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yashwant](https://avatars.discourse-cdn.com/v4/letter/y/58956e/32.png) [@yashwant](https://discuss.elastic.co/u/yashwant)\
**Post date:** [November 27, 2019, 7:06am UTC](https://discuss.elastic.co/t/how-can-i-properly-create-an-index-in-elasticsearch-using-ruby/209620/1 "2019-11-27T07:06:33Z")

</div>

Hello,

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 = Elasticsearch::Client.new 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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 25, 2019, 7:06am UTC](https://discuss.elastic.co/t/how-can-i-properly-create-an-index-in-elasticsearch-using-ruby/209620/2 "2019-12-25T07:06:39Z")

</div>

Closed on December 25, 2019, 7:06am UTC

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