# Performance about api between http api and java api?

**URL:** https://discuss.elastic.co/t/performance-about-api-between-http-api-and-java-api/20273
**Category:** Elasticsearch
**Created:** [October 16, 2014, 2:27am UTC](https://discuss.elastic.co/t/performance-about-api-between-http-api-and-java-api/20273 "2014-10-16T02:27:31Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zouxcs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zouxcs/32/920_2.png) [@zouxcs](https://discuss.elastic.co/u/zouxcs)
#### Post date: [October 16, 2014, 2:27am UTC](https://discuss.elastic.co/t/performance-about-api-between-http-api-and-java-api/20273/1 "2014-10-16T02:27:31Z")

</div>

I want to partial update doc,but i also want a good performace,so I tried 2 way to test ,one is by http rest api,the other is by java api version0.90;  
java\_version:1.6.20  
es\_version:0.90.1

HTTP REST:  
[http://127.0.0.1:9200/\_bulk](http://127.0.0.1:9200/_bulk)

{"update":{"\_index":"mobile","\_type":"mobile\_property\_mid","\_id":"15141307986"}} /n  
{"doc":{"consume\_vol\_tot":"0.0","last\_login\_date":"2012-06-27","login\_days\_3month":"0","log\_avg\_interval\_half\_year":"0.0","consume\_days\_3month":"0"}} /n  
{"update":{"\_index":"mobile","\_type":"mobile\_property\_mid","\_id":"15141308091"}} /n  
{"doc":{"consume\_vol\_tot":"0.0","last\_login\_date":"2012-12-26","login\_days\_3month":"0","log\_avg\_interval\_half\_year":"0.0","consume\_days\_3month":"0"}} /n

JAVA API:

bulkRequest.add(client.prepareUpdate(indexName, indexTypeName,key).setUpsertRequest(builder.endObject()).setScript(updateScript.toString()).setFields("\_source"));  
BulkResponse bulkResponse = bulkRequest.execute().actionGet();

Here is the test result:  
http rest：  
bulk nums:8000,cost time:1306  
bulk nums:8000,cost time:1348  
bulk nums:8000,cost time:1320  
bulk nums:8000,cost time:1277  
bulk nums:8000,cost time:1214  
bulk nums:8000,cost time:1336  
bulk nums:8000,cost time:1338  
bulk nums:8000,cost time:1399  
bulk nums:8000,cost time:1231  
bulk nums:8000,cost time:1280  
bulk nums:8000,cost time:1482  
bulk nums:8000,cost time:1248  
bulk nums:8000,cost time:1394

java api：  
bulkResponse items8000,cost time:5252  
bulkResponse items8000,cost time:5171  
bulkResponse items8000,cost time:5077  
bulkResponse items8000,cost time:5230  
bulkResponse items8000,cost time:5469  
bulkResponse items8000,cost time:5898  
bulkResponse items8000,cost time:5443  
bulkResponse items8000,cost time:5579  
bulkResponse items8000,cost time:5026  
bulkResponse items8000,cost time:5279  
bulkResponse items8000,cost time:5851  
bulkResponse items8000,cost time:5708  
bulkResponse items8000,cost time:5115

So why is java api way so slower than http?  
And How can I slove it?I read l a lot doc,but can't found the answer.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 16, 2014, 6:28am UTC](https://discuss.elastic.co/t/performance-about-api-between-http-api-and-java-api/20273/2 "2014-10-16T06:28:59Z")

</div>

What do you have in updateScript?

Sounds like you were not using script with HTTP REST requests.

David

> Le 16 oct. 2014 à 04:28, Charles Chou [zouxcs@gmail.com](mailto:zouxcs@gmail.com) a écrit :
> 
> I want to partial update doc,but i also want a good performace,so I tried 2 way to test ,one is by http rest api,the other is by java api version0.90;  
> java\_version:1.6.20  
> es\_version:0.90.1
> 
> HTTP REST:  
> [http://127.0.0.1:9200/\_bulk](http://127.0.0.1:9200/_bulk)
> 
> {"update":{"\_index":"mobile","\_type":"mobile\_property\_mid","\_id":"15141307986"}} /n  
> {"doc":{"consume\_vol\_tot":"0.0","last\_login\_date":"2012-06-27","login\_days\_3month":"0","log\_avg\_interval\_half\_year":"0.0","consume\_days\_3month":"0"}} /n  
> {"update":{"\_index":"mobile","\_type":"mobile\_property\_mid","\_id":"15141308091"}} /n  
> {"doc":{"consume\_vol\_tot":"0.0","last\_login\_date":"2012-12-26","login\_days\_3month":"0","log\_avg\_interval\_half\_year":"0.0","consume\_days\_3month":"0"}} /n
> 
> JAVA API:
> 
> bulkRequest.add(client.prepareUpdate(indexName, indexTypeName,key).setUpsertRequest(builder.endObject()).setScript(updateScript.toString()).setFields("\_source"));  
> BulkResponse bulkResponse = bulkRequest.execute().actionGet();
> 
> Here is the test result:  
> http rest：  
> bulk nums:8000,cost time:1306  
> bulk nums:8000,cost time:1348  
> bulk nums:8000,cost time:1320  
> bulk nums:8000,cost time:1277  
> bulk nums:8000,cost time:1214  
> bulk nums:8000,cost time:1336  
> bulk nums:8000,cost time:1338  
> bulk nums:8000,cost time:1399  
> bulk nums:8000,cost time:1231  
> bulk nums:8000,cost time:1280  
> bulk nums:8000,cost time:1482  
> bulk nums:8000,cost time:1248  
> bulk nums:8000,cost time:1394
> 
> java api：  
> bulkResponse items8000,cost time:5252  
> bulkResponse items8000,cost time:5171  
> bulkResponse items8000,cost time:5077  
> bulkResponse items8000,cost time:5230  
> bulkResponse items8000,cost time:5469  
> bulkResponse items8000,cost time:5898  
> bulkResponse items8000,cost time:5443  
> bulkResponse items8000,cost time:5579  
> bulkResponse items8000,cost time:5026  
> bulkResponse items8000,cost time:5279  
> bulkResponse items8000,cost time:5851  
> bulkResponse items8000,cost time:5708  
> bulkResponse items8000,cost time:5115
> 
> ## So why is java api way so slower than http? And How can I slove it?I read l a lot doc,but can't found the answer.
> 
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0d152ecb-d141-483b-a0ef-48b7f6bcc11a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0d152ecb-d141-483b-a0ef-48b7f6bcc11a%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4A44464D-AB1C-4385-ADDC-8BC2DC5B49BF%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/4A44464D-AB1C-4385-ADDC-8BC2DC5B49BF%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![zouxcs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zouxcs/32/920_2.png) [@zouxcs](https://discuss.elastic.co/u/zouxcs)
#### Post date: [October 17, 2014, 1:55am UTC](https://discuss.elastic.co/t/performance-about-api-between-http-api-and-java-api/20273/3 "2014-10-17T01:55:39Z")

</div>

yeah,I found this also can partial update the doc.  
but when I change the doc to script int http rest ,I found this way  
couldn't finish the update successfully

On Thursday, October 16, 2014 2:29:08 PM UTC+8, David Pilato wrote:

> What do you have in updateScript?
> 
> Sounds like you were not using script with HTTP REST requests.
> 
> David
> 
> Le 16 oct. 2014 à 04:28, Charles Chou \<[zou...@gmail.com](mailto:zou...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> I want to partial update doc,but i also want a good performace,so I tried  
> 2 way to test ,one is by http rest api,the other is by java api  
> version0.90;  
> java\_version:1.6.20  
> es\_version:0.90.1
> 
> HTTP REST:  
> [http://127.0.0.1:9200/\_bulk](http://127.0.0.1:9200/_bulk)
> 
> {"update":{"\_index":"mobile","\_type":"mobile\_property\_mid","\_id":"15141307986"}}  
> /n  
> {"doc":{"consume\_vol\_tot":"0.0","last\_login\_date":"2012-06-27","login\_days\_3month":"0","log\_avg\_interval\_half\_year":"0.0","consume\_days\_3month":"0"}}  
> /n  
> {"update":{"\_index":"mobile","\_type":"mobile\_property\_mid","\_id":"15141308091"}}  
> /n  
> {"doc":{"consume\_vol\_tot":"0.0","last\_login\_date":"2012-12-26","login\_days\_3month":"0","log\_avg\_interval\_half\_year":"0.0","consume\_days\_3month":"0"}}  
> /n
> 
> JAVA API:
> 
> bulkRequest.add(client.prepareUpdate(indexName,  
> indexTypeName,key).setUpsertRequest(builder.endObject()).setScript(updateScript.toString()).setFields("\_source"));  
> BulkResponse bulkResponse = bulkRequest.execute().actionGet();
> 
> Here is the test result:  
> http rest：  
> bulk nums:8000,cost time:1306  
> bulk nums:8000,cost time:1348  
> bulk nums:8000,cost time:1320  
> bulk nums:8000,cost time:1277  
> bulk nums:8000,cost time:1214  
> bulk nums:8000,cost time:1336  
> bulk nums:8000,cost time:1338  
> bulk nums:8000,cost time:1399  
> bulk nums:8000,cost time:1231  
> bulk nums:8000,cost time:1280  
> bulk nums:8000,cost time:1482  
> bulk nums:8000,cost time:1248  
> bulk nums:8000,cost time:1394
> 
> java api：  
> bulkResponse items8000,cost time:5252  
> bulkResponse items8000,cost time:5171  
> bulkResponse items8000,cost time:5077  
> bulkResponse items8000,cost time:5230  
> bulkResponse items8000,cost time:5469  
> bulkResponse items8000,cost time:5898  
> bulkResponse items8000,cost time:5443  
> bulkResponse items8000,cost time:5579  
> bulkResponse items8000,cost time:5026  
> bulkResponse items8000,cost time:5279  
> bulkResponse items8000,cost time:5851  
> bulkResponse items8000,cost time:5708  
> bulkResponse items8000,cost time:5115
> 
> So why is java api way so slower than http?  
> And How can I slove it?I read l a lot doc,but can't found the answer.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/0d152ecb-d141-483b-a0ef-48b7f6bcc11a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0d152ecb-d141-483b-a0ef-48b7f6bcc11a%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/0d152ecb-d141-483b-a0ef-48b7f6bcc11a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/0d152ecb-d141-483b-a0ef-48b7f6bcc11a%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/92345cac-5274-436a-be12-90b92a99e406%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/92345cac-5274-436a-be12-90b92a99e406%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:55am UTC](https://discuss.elastic.co/t/performance-about-api-between-http-api-and-java-api/20273/4 "2017-07-06T00:55:37Z")

</div>


