# How to improve performance of application for inserting list in elasticSearch?

**URL:** <https://discuss.elastic.co/t/how-to-improve-performance-of-application-for-inserting-list-in-elasticsearch/63982>\
**Category:** Elasticsearch\
**Created:** [October 26, 2016, 9:49am UTC](https://discuss.elastic.co/t/how-to-improve-performance-of-application-for-inserting-list-in-elasticsearch/63982 "2016-10-26T09:49:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vrushali](https://avatars.discourse-cdn.com/v4/letter/v/dfb087/32.png) [@Vrushali](https://discuss.elastic.co/u/Vrushali)\
**Post date:** [October 26, 2016, 9:49am UTC](https://discuss.elastic.co/t/how-to-improve-performance-of-application-for-inserting-list-in-elasticsearch/63982/1 "2016-10-26T09:49:19Z")

</div>

I have 2000 entries in my List and trying to insert this list into elasticsearch by API which is nothing but a bulk request.  
Please find below code for the same.

for(Car car : carList){  
elasticSearchService.addOrganization(car,"Car");  
}

@Autowired  
private Client esClient;

private void addOrganization(Object object, String modelName){  
Gson gson = new Gson();  
final String json = gson.toJson(object);  
esClient.prepareIndex("ElasticSearchIndex", modelName).setSource(json).execute().actionGet();  
}

I have made following entry in elasticsearch.yml file  
threadpool:  
index:  
size: 250  
queue\_size: 1000

As we are monitoring performance of the application through JMeter, we found that our application generates 2000 HTTP requests to connect and put data in elasticsearch  
which takes around 10 seconds for this task.Can we make connectionpool in esClient or is there any way to do configuration at elasticsearch server so that performance of the application can be improved and  
response time will be reduced upto 3 seconds?

---

<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:** [October 26, 2016, 11:21am UTC](https://discuss.elastic.co/t/how-to-improve-performance-of-application-for-inserting-list-in-elasticsearch/63982/2 "2016-10-26T11:21:42Z")

</div>

Hi @Vrushali,

> [@Vrushali](#):
>
> As we are monitoring performance of the application through JMeter, we found that our application generates 2000 HTTP requests to connect and put data in elasticsearch

These are not bulk requests. You are indexing each document in an explicit request and this kills your performance. You can use [`BulkProcessor`](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-bulk-processor.html) which offers a more high-level API and helps you sending bulk requests. Then your indexing throughput should be much better.

Daniel

---

<div class="post-metadata">

**Author:** ![xavierfacq](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavierfacq/32/8744_2.png) [@xavierfacq](https://discuss.elastic.co/u/xavierfacq)\
**Post date:** [October 26, 2016, 12:19pm UTC](https://discuss.elastic.co/t/how-to-improve-performance-of-application-for-inserting-list-in-elasticsearch/63982/3 "2016-10-26T12:19:36Z")

</div>

Hi, you are not using the bulk API, here is the way to do it :

```
		BulkRequestBuilder bulkRequest = esClient.prepareBulk();
		bulkRequest.setRefresh(false);

		for(Car car : carList){
					Gson gson = new Gson();
					final String json = gson.toJson(object);
					IndexRequestBuilder indexRequestBuilder = esClient.prepareIndex("ElasticSearchIndex", modelName).setSource(json).execute().actionGet();

					bulkRequest.add(indexRequestBuilder);
		}
		BulkResponse response = bulkRequest.execute().actionGet();

```

Xavier

---

<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:09pm UTC](https://discuss.elastic.co/t/how-to-improve-performance-of-application-for-inserting-list-in-elasticsearch/63982/4 "2017-07-05T22:09:30Z")

</div>


