# Elasticsearch is taking longer time while doing update and search simultaneously

**URL:** <https://discuss.elastic.co/t/elasticsearch-is-taking-longer-time-while-doing-update-and-search-simultaneously/19410>\
**Category:** Elasticsearch\
**Created:** [August 22, 2014, 1:30pm UTC](https://discuss.elastic.co/t/elasticsearch-is-taking-longer-time-while-doing-update-and-search-simultaneously/19410 "2014-08-22T13:30:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bagui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bagui/32/960_2.png) [@bagui](https://discuss.elastic.co/u/bagui)\
**Post date:** [August 22, 2014, 1:30pm UTC](https://discuss.elastic.co/t/elasticsearch-is-taking-longer-time-while-doing-update-and-search-simultaneously/19410/1 "2014-08-22T13:30:30Z")

</div>

Hi,

I'm doing update in elasticsearch document and the same time one rest api  
is calling for search results. Below is my code.

public String updateElasticsearchDocument(String index, String type,  
List indexID) {  
Client client = ESClientFactory.getInstance();  
UpdateResponse updateResponse = null;  
JSONObject jsonResponse = new JSONObject();  
JSONObject json =new JSONObject();  
int i=1;  
try {  
for(String id : indexID)  
{  
updateResponse = client.prepareUpdate(index, type, id)  
.setDoc(jsonBuilder()  
.startObject().field("view\_mode", "read")  
.endObject())  
.setDocAsUpsert(true)  
.setFields("\_source")  
.setTimeout("10000")  
.execute().actionGet();  
logger.info("updating the document for type= "+ updateResponse.getType()+  
" for id= "+ updateResponse.getId());

json.put("indexID"+i, updateResponse.getId());  
i++;  
}  
jsonResponse.put("updated\_index", json);  
} catch (ActionRequestValidationException e) {  
logger.warn(this.getClass().getName() + ":" + "updateDocument: "

- e.getMessage(), e);  
}  
catch (ElasticsearchException e) {  
logger.warn(this.getClass().getName() + ":" + "updateDocument: "
- e.getMessage(), e);  
e.printStackTrace();  
} catch (IOException e) {  
logger.warn(this.getClass().getName() + ":" + "updateDocument: "
- e.getMessage(), e);  
} catch (JSONException e) {  
// TODO Auto-generated catch block  
e.printStackTrace();  
}  
return jsonResponse.toString();  
}

_the search query is :_

POST /monitoring/quota-management/\_search

```
{
      "query": {"match": {
          "view_mode": "read"
       }}, 
    "sort": [
       {
          "_timestamp": {
             "order": "desc"
          }
       }
    ],
    "size": 10
}

```

Now, I have to wait for like 40-50 seconds to get the updated search  
result. This is affecting the production application.  
Please let me know what needs to be done here to minimizes the time taken.

Thanks,  
Subhadip

--  
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/945425a0-69c2-46bd-b63f-a23bc6dc455c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/945425a0-69c2-46bd-b63f-a23bc6dc455c%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vineeth_mohan_2/32/747_2.png) [@vineeth\_mohan\_2](https://discuss.elastic.co/u/vineeth_mohan_2)\
**Post date:** [August 22, 2014, 5:55pm UTC](https://discuss.elastic.co/t/elasticsearch-is-taking-longer-time-while-doing-update-and-search-simultaneously/19410/2 "2014-08-22T17:55:28Z")

</div>

Hello Subhadip\* , \*

What exactly are you trying to achieve using this code.

updateResponse = client.prepareUpdate(index, type, id)  
.setDoc(jsonBuilder()  
.startObject().field("view\_mode", "read")  
.endObject())  
.setDocAsUpsert(true)  
.setFields("\_source")  
.setTimeout("10000")

I was wondering where the modification data is given.

Thanks  
Vineeth

On Fri, Aug 22, 2014 at 7:00 PM, Subhadip Bagui [i.bagui@gmail.com](mailto:i.bagui@gmail.com) wrote:

> Hi,
> 
> I'm doing update in elasticsearch document and the same time one rest api  
> is calling for search results. Below is my code.
> 
> public String updateElasticsearchDocument(String index, String type,  
> List indexID) {  
> Client client = ESClientFactory.getInstance();  
> UpdateResponse updateResponse = null;  
> JSONObject jsonResponse = new JSONObject();  
> JSONObject json =new JSONObject();  
> int i=1;  
> try {  
> for(String id : indexID)  
> {  
> updateResponse = client.prepareUpdate(index, type, id)  
> .setDoc(jsonBuilder()  
> .startObject().field("view\_mode", "read")  
> .endObject())  
> .setDocAsUpsert(true)  
> .setFields("\_source")  
> .setTimeout("10000")  
> .execute().actionGet();  
> logger.info("updating the document for type= "+  
> updateResponse.getType()+ " for id= "+ updateResponse.getId());
> 
> json.put("indexID"+i, updateResponse.getId());  
> i++;  
> }  
> jsonResponse.put("updated\_index", json);  
> } catch (ActionRequestValidationException e) {  
> logger.warn(this.getClass().getName() + ":" + "updateDocument: "
> 
> - e.getMessage(), e);  
> }  
> catch (ElasticsearchException e) {  
> logger.warn(this.getClass().getName() + ":" + "updateDocument: "
> - e.getMessage(), e);  
> e.printStackTrace();  
> } catch (IOException e) {  
> logger.warn(this.getClass().getName() + ":" + "updateDocument: "
> - e.getMessage(), e);  
> } catch (JSONException e) {  
> // TODO Auto-generated catch block  
> e.printStackTrace();  
> }  
> return jsonResponse.toString();  
> }
> 
> _the search query is :_
> 
> POST /monitoring/quota-management/\_search
> 
> ```
> {
> "query": {"match": {
> "view_mode": "read"
> }},
> "sort": [
> {
> "_timestamp": {
> "order": "desc"
> }
> }
> ],
> "size": 10
> }
> 
> ```
> 
> Now, I have to wait for like 40-50 seconds to get the updated search  
> result. This is affecting the production application.  
> Please let me know what needs to be done here to minimizes the time taken.
> 
> Thanks,  
> Subhadip
> 
> --  
> 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/945425a0-69c2-46bd-b63f-a23bc6dc455c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/945425a0-69c2-46bd-b63f-a23bc6dc455c%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/945425a0-69c2-46bd-b63f-a23bc6dc455c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/945425a0-69c2-46bd-b63f-a23bc6dc455c%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/CAGdPd5kp10tiuNpPN4wW1mso\_-MLxfB1zBZULM%2BpSeSG6o75dg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGdPd5kp10tiuNpPN4wW1mso_-MLxfB1zBZULM%2BpSeSG6o75dg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![bagui](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bagui/32/960_2.png) [@bagui](https://discuss.elastic.co/u/bagui)\
**Post date:** [December 8, 2014, 7:33pm UTC](https://discuss.elastic.co/t/elasticsearch-is-taking-longer-time-while-doing-update-and-search-simultaneously/19410/3 "2014-12-08T19:33:59Z")

</div>

Hi,

In this code I'm trying to update the field "view\_mode" value as "read".

On Friday, August 22, 2014 11:25:45 PM UTC+5:30, vineeth mohan wrote:

> Hello Subhadip\* , \*
> 
> What exactly are you trying to achieve using this code.
> 
> updateResponse = client.prepareUpdate(index, type, id)  
> .setDoc(jsonBuilder()  
> .startObject().field("view\_mode", "read")  
> .endObject())  
> .setDocAsUpsert(true)  
> .setFields("\_source")  
> .setTimeout("10000")
> 
> I was wondering where the modification data is given.
> 
> Thanks  
> Vineeth
> 
> On Fri, Aug 22, 2014 at 7:00 PM, Subhadip Bagui \<[i.b...@gmail.com](mailto:i.b...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi,
> > 
> > I'm doing update in elasticsearch document and the same time one rest api  
> > is calling for search results. Below is my code.
> > 
> > public String updateElasticsearchDocument(String index, String type,  
> > List indexID) {  
> > Client client = ESClientFactory.getInstance();  
> > UpdateResponse updateResponse = null;  
> > JSONObject jsonResponse = new JSONObject();  
> > JSONObject json =new JSONObject();  
> > int i=1;  
> > try {  
> > for(String id : indexID)  
> > {  
> > updateResponse = client.prepareUpdate(index, type, id)  
> > .setDoc(jsonBuilder()  
> > .startObject().field("view\_mode", "read")  
> > .endObject())  
> > .setDocAsUpsert(true)  
> > .setFields("\_source")  
> > .setTimeout("10000")  
> > .execute().actionGet();  
> > logger.info("updating the document for type= "+  
> > updateResponse.getType()+ " for id= "+ updateResponse.getId());
> > 
> > json.put("indexID"+i, updateResponse.getId());  
> > i++;  
> > }  
> > jsonResponse.put("updated\_index", json);  
> > } catch (ActionRequestValidationException e) {  
> > logger.warn(this.getClass().getName() + ":" + "updateDocument: "
> > 
> > - e.getMessage(), e);  
> > }  
> > catch (ElasticsearchException e) {  
> > logger.warn(this.getClass().getName() + ":" + "updateDocument: "
> > - e.getMessage(), e);  
> > e.printStackTrace();  
> > } catch (IOException e) {  
> > logger.warn(this.getClass().getName() + ":" + "updateDocument: "
> > - e.getMessage(), e);  
> > } catch (JSONException e) {  
> > // TODO Auto-generated catch block  
> > e.printStackTrace();  
> > }  
> > return jsonResponse.toString();  
> > }
> > 
> > _the search query is :_
> > 
> > POST /monitoring/quota-management/\_search
> > 
> > ```
> > {
> > "query": {"match": {
> > "view_mode": "read"
> > }}, 
> > "sort": [
> > {
> > "_timestamp": {
> > "order": "desc"
> > }
> > }
> > ],
> > "size": 10
> > }
> > 
> > ```
> > 
> > Now, I have to wait for like 40-50 seconds to get the updated search  
> > result. This is affecting the production application.  
> > Please let me know what needs to be done here to minimizes the time taken.
> > 
> > Thanks,  
> > Subhadip
> > 
> > --  
> > 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/945425a0-69c2-46bd-b63f-a23bc6dc455c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/945425a0-69c2-46bd-b63f-a23bc6dc455c%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/945425a0-69c2-46bd-b63f-a23bc6dc455c%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/945425a0-69c2-46bd-b63f-a23bc6dc455c%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/e1485ab2-6aac-4ef2-830d-5d11123fd7f6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e1485ab2-6aac-4ef2-830d-5d11123fd7f6%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:44am UTC](https://discuss.elastic.co/t/elasticsearch-is-taking-longer-time-while-doing-update-and-search-simultaneously/19410/4 "2017-07-06T00:44:53Z")

</div>


