3

We are doing some manipulation and after that we are trying to insert data in to elastic DB. My problem is, few records are getting inserted into the index and few are missing. I can see the data in my log file, and i have no elastic error also. Since there is no error , I could not debug also. Even without inserting , customers are getting the response. Below is my code.

 file.js
 async function InsertModelES() {
    var objn= {
        PID: ID,
        TID: MID,
        UserID:userID,
        HID: HrID,
    };
    await elasticClient.index({
        index: 'scrn', 
        type: '_doc',
        id: ID ,
        body: objn
    }, function (err, data) { 
    if (err) {
        console.log("err ", err)
    }
    else {
    } 
 })  

 app.js
 
 app.post('/allrequest', async function(req, res){ 
  let result = await file1.allrequest(data,urn);
  await file1.InsertModelES()
  res.send(result);  
 }

This problem only happens, when the load is high. What could be the reason?

2 Answers 2

2

It is erratic, and as you said "it happens when the load is high". It will probably fix the problem if you will set refresh=true when indexing the new document.

From Index API:

refresh (Optional, enum) If true, Elasticsearch refreshes the affected shards to make this operation visible to search, if wait_for then wait for a refresh to make this operation visible to search, if false do nothing with refreshes. Valid values: true, false, wait_for. Default: false.

Sign up to request clarification or add additional context in comments.

Comments

1

The bulk API makes it possible to perform many index/delete operations in a single API call. This can greatly increase the indexing speed. https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/bulk_examples.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.