This seems to accomplish what you want, if I'm understanding you correctly:
var arr_1 = ["row1", "row2", "row3", "row4"];
var arr_2 = ["field1", "field2", "field3", "field4"];
var doc_body = {};
arr_1.map(function(val, idx){ doc_body[val] = arr_2[idx]; });
client.index({
index: 'test_index',
type: 'mytype',
id: '1',
body: doc_body
});
Here is a self-contained html document that implements it:
<html>
<head>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/elasticsearch/3.0.2/elasticsearch.jquery.min.js"></script>
</head>
<body>
<div><button id="delete_index_btn">Delete Index</button></div>
<div><button id="create_index_btn">Create Index</button></div>
<div><button id="add_docs_btn">Add Docs</button></div>
<div>
<h3>Response:</h3>
<pre id="response"></pre>
</div>
<script type="text/javascript">
$(function(){
var client = new $.es.Client({
hosts: 'localhost:9200'
});
$("#delete_index_btn").click(function(){
client.indices.delete({
index: 'test_index'
}).then(function(resp){
$("#response").append("\nclient.indices.delete: " + JSON.stringify(resp));
}, function(err){
$("#response").append("\nclient.indices.delete ERROR: " + JSON.stringify(err));
});
});
$("#create_index_btn").click(function(){
client.indices.create({
index: 'test_index'
}).then(function(resp){
$("#response").append("\nclient.indices.create: " + JSON.stringify(resp));
}, function(err){
$("#response").append("\nclient.indices.create ERROR: " + JSON.stringify(err));
});
});
$("#add_docs_btn").click(function(){
var arr_1 = ["row1", "row2", "row3", "row4"];
var arr_2 = ["field1", "field2", "field3", "field4"];
var doc_body = {};
arr_1.map(function(val, idx){ doc_body[val] = arr_2[idx]; });
client.index({
index: 'test_index',
type: 'mytype',
id: '1',
body: doc_body
}).then(function(resp){
$("#response").append("\nclient.index: " + JSON.stringify(resp));
}, function(err){
$("#response").append("\nclient.index ERROR: " + JSON.stringify(err));
});
});
});
</script>
</body>
</html>
Does that solve your problem?