# How to take create, using Javascript, an Index in Elasticsearch using a CSV file?

**URL:** <https://discuss.elastic.co/t/how-to-take-create-using-javascript-an-index-in-elasticsearch-using-a-csv-file/21522>\
**Category:** Elasticsearch\
**Created:** [January 7, 2015, 11:51am UTC](https://discuss.elastic.co/t/how-to-take-create-using-javascript-an-index-in-elasticsearch-using-a-csv-file/21522 "2015-01-07T11:51:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![docM](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@docM](https://discuss.elastic.co/u/docM)\
**Post date:** [January 7, 2015, 11:51am UTC](https://discuss.elastic.co/t/how-to-take-create-using-javascript-an-index-in-elasticsearch-using-a-csv-file/21522/1 "2015-01-07T11:51:46Z")

</div>

Hi everybody,

Using Javascript, I want to create an Index in Elasticsearch from a csv file.  
I put the name of each column (header) in a different position of an array and every field of each  
row in another array. How should I "fill" the body of the index? Let's say  
a have:

arr\_1 = [row1, row2, row3, row4];  
arr\_2 = [field1, field2, field3, field4];

then I want something like:

client.index(  
index: name\_index,  
type: name\_type,  
body: {  
row1 : field1; //arr1\_[1] : arr\_2[1],  
row2 : field2; //arr1\_[2] : arr\_2[2],  
.....  
....  
})

My (wrong!!!) solution is more or less:

for (var i = 0; i \< arr\_1.length; i++){  
row = arr\_1[i];

```
field = arr_2[i]:

var bodyContents = {
    row : field /*this should give me at the end row1 : field1; //arr1_[1] : arr_2[1],

                                                           row2 : field2; //arr1_[2] : arr_2[2],

```

..... }; } client.index( { index: index\_name, type: type\_name, body:  
bodyContents }, function (error) { [.....]

```
}

```

);

Can anyone help me in some way? thanks in advance.

---

<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:** [July 6, 2017, 12:40am UTC](https://discuss.elastic.co/t/how-to-take-create-using-javascript-an-index-in-elasticsearch-using-a-csv-file/21522/2 "2017-07-06T00:40:19Z")

</div>


