1

I am using npm elasticsearch, in that getting an error like this

client.index is not a function

here is my code

    encryptObj = enpyt.encrypt(function(encrypted){
         client.index({ 
            index: 'collectionnew3
            id: '101',
            type: 'collectiontype3',
            body: {
              "username": "postgres",
              "pswrd": encrypted,

            }
          },function(err,resp,status) {
                console.log(resp);
         })
      })

Any idea why am I getting this?

2
  • How are you getting client?, the error is because it doesn't have index as a function. Could you show how are you getting client? Commented Feb 15, 2017 at 7:21
  • @Hosar I used to to export the client using exports.client its not worked so I used module.exports to export the client in my main.js now problem solved Commented Feb 15, 2017 at 8:51

1 Answer 1

1

As said in comments, it seems that client is not properly instantiated.

Example to instantiate an Elasticsearch client in node.js:

var elasticsearch = require('elasticsearch');

var client = new elasticsearch.Client({
    host: "http://localhost:9200",
    apiVersion: "2.3"
});

Update host and apiVersion with your configuration.

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

1 Comment

,yes as you said the client is not instantiated properly because I made mistake while importing the client from another file now I used module.export to export the client

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.