# How to read a file from JMETER in node.js and index into elasticsearch?

**URL:** <https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401>\
**Category:** Elasticsearch\
**Created:** [July 13, 2016, 11:35am UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401 "2016-07-13T11:35:04Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeevan\_jeevanreddy](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jeevan\_jeevanreddy](https://discuss.elastic.co/u/jeevan_jeevanreddy)\
**Post date:** [July 13, 2016, 11:35am UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/1 "2016-07-13T11:35:04Z")

</div>

I am using node.js to index a file into elasticsearch.  
i am trying to give input as a file from jmeter? i.e.., as **req.file**  
but it giving output as undefined.  
can anyone specify the better solution?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [July 13, 2016, 1:05pm UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/2 "2016-07-13T13:05:45Z")

</div>

Hi,

sounds like you want to benchmark your cluster. We have built [Rally](https://github.com/elastic/rally) for exactly that purpose. In your case you'd need to [create your own track](https://esrally.readthedocs.io/en/latest/adding_benchmarks.html) based on your input file (in line with the general racing vocabulary we call the benchmark description a "track" in Rally).

Just check whether this fits your use case and feel free to ask questions about Rally in this forum.

Daniel

---

<div class="post-metadata">

**Author:** ![jeevan\_jeevanreddy](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jeevan\_jeevanreddy](https://discuss.elastic.co/u/jeevan_jeevanreddy)\
**Post date:** [July 14, 2016, 3:07am UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/3 "2016-07-14T03:07:53Z")

</div>

thanks for your reply daniel.  
i need to index document first through node.js later on benchmark

---

<div class="post-metadata">

**Author:** ![jettro](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jettro/32/3418_2.png) [@jettro](https://discuss.elastic.co/u/jettro)\
**Post date:** [July 14, 2016, 5:59am UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/4 "2016-07-14T05:59:50Z")

</div>

Can you show a bit more of what you are trying to accomplish? Do you have some node.js code that you are using?

We generally use jmeter in combination with logstash, or if you do not mind using alpha software / use ingest. A bit of information about ingest can be found in a blogpost a colleague of mine wrote: [https://amsterdam.luminis.eu/2016/04/01/just-tailing-a-file-exploring-new-elasticsearchs-ingest/](https://amsterdam.luminis.eu/2016/04/01/just-tailing-a-file-exploring-new-elasticsearchs-ingest/)

---

<div class="post-metadata">

**Author:** ![jeevan\_jeevanreddy](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jeevan\_jeevanreddy](https://discuss.elastic.co/u/jeevan_jeevanreddy)\
**Post date:** [July 14, 2016, 6:28am UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/5 "2016-07-14T06:28:34Z")

</div>

node.js code which i am using in the project

var http = require('http');  
var express = require('express');  
var app = express();  
var CircularJSON = require('circular-json');  
var elasticsearch = require('elasticsearch');  
var client = new elasticsearch.Client({  
host: 'IP:port',  
log: 'trace'  
});  
http.createServer(app).listen(1000);

var bodyParser = require('body-parser');  
app.use(bodyParser.urlencoded({  
extended: true  
}));  
app.use(bodyParser.json());  
app.post('/post/:index/:type/:id/', function(req, res){  
var fs = require("fs");  
fs.writeFile('inpu.json',req.file);  
client.index({  
index: req.params.index,  
type: req.params.type,  
id: [req.params.id](http://req.params.id),  
body:JSON.parse(fs.readFileSync(\_\_dirname +'/inpu.json'))  
},function (error, response) {  
console.log(response);  
res.send(response);  
});  
});

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [July 14, 2016, 6:41am UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/6 "2016-07-14T06:41:25Z")

</div>

Hi,

I don't know much about Javascript but this code seems just to act as some kind of proxy and as far as I understand it, it also has a race condition. It will fail if two concurrent requests come in because it relies that it owns the file `inpu.json` (typo?) exclusively. Why do you need this at all?

Also, it is not clear to me what the file contains. Just one document?

If you want to index a lot of documents at once, you should use the [bulk API](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html) otherwise performance will suffer badly.

W.r.t. to your original question: I don't use JMeter these days but [the JMeter docs](https://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request_parms1) indicate to me that file upload should be doable with the `File Path` parameter.

Daniel

---

<div class="post-metadata">

**Author:** ![jeevan\_jeevanreddy](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jeevan\_jeevanreddy](https://discuss.elastic.co/u/jeevan_jeevanreddy)\
**Post date:** [July 14, 2016, 6:44am UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/7 "2016-07-14T06:44:01Z")

</div>

![](https://us1.discourse-cdn.com/elastic/original/2X/6/6f998c74a3f3ed4cb86bf1baa7c8779f32711419.png)

i am giving input in file upload space to node.js code from jmeter

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [July 14, 2016, 6:48am UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/8 "2016-07-14T06:48:20Z")

</div>

Hi,

I guess you don't really upload `C:/video1.file` as indicated by your screenshot, right? 🙂

How does the document look like and what is the problem? You wrote initially that you get "undefined" (where?). Sounds like a problem in your node.js code? Did you try indexing directly into Elasticsearch?

Daniel

---

<div class="post-metadata">

**Author:** ![jeevan\_jeevanreddy](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jeevan\_jeevanreddy](https://discuss.elastic.co/u/jeevan_jeevanreddy)\
**Post date:** [July 14, 2016, 6:52am UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/9 "2016-07-14T06:52:28Z")

</div>

ya i tried uploading directly to elasticsearch  
it worked fine.

file contains video data in base64 format.

the problem is in my code. i need a solution for that.

getting undefined in inpu.json while reading from jmeter using req.file

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [July 14, 2016, 6:57am UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/10 "2016-07-14T06:57:59Z")

</div>

Hi,

I am sorry but solving a Javascript problem is quite offtopic here, no?. 😉 I suggest you better try some Javascript related forum. There will be people that are much more knowledgeable and I am sure they are able to answer your Javascript question. 🙂

Daniel

---

<div class="post-metadata">

**Author:** ![jeevan\_jeevanreddy](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@jeevan\_jeevanreddy](https://discuss.elastic.co/u/jeevan_jeevanreddy)\
**Post date:** [July 14, 2016, 6:58am UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/11 "2016-07-14T06:58:24Z")

</div>

ok thanks for your time

---

<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 5, 2017, 10:35pm UTC](https://discuss.elastic.co/t/how-to-read-a-file-from-jmeter-in-node-js-and-index-into-elasticsearch/55401/12 "2017-07-05T22:35:51Z")

</div>


