Failure to index documents to App Search using Node.JS

I am using Node JS with App Search 7.11.1 hosted on ECE 2.8.1. The following is the code to create an App Search client and to index a document. It is based on the official Elastic App Search NPM site.

const AppSearchClient = require('@elastic/app-search-node')

let documents = jsonDataLoader.loadJsonFile("C:\\Git\\SPS\\data\\jsondata.json");
const baseUrlFn = () => 'https://103e575486674f74bXXXXXXXXXXXXXXX.ece-playground.dev.sg:9243/api/as/v1/';
var asClient = new AppSearchClient(undefined, 'private-8bgcft2h2x2h1uXXXXXXXXXX', baseUrlFn);

for (const doc of documents) {  
    asClient.indexDocument('sharepoint-tap', JSON.stringify(doc))
            .then(response => console.log(response))
            .catch(error => console.log(error))
}

Upon running the code, there is a certificate error.

{ Error: unable to verify the first certificate
at TLSSocket. (_tls_wrap.js:1103:38)
at emitNone (events.js:106:13)
at TLSSocket.emit (events.js:208:7)
at TLSSocket._finishInit (_tls_wrap.js:637:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:467:38)
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
errorMessages: [ 'unable to verify the first certificate' ] }
{ Error: unable to verify the first certificate
at TLSSocket. (_tls_wrap.js:1103:38)
at emitNone (events.js:106:13)
at TLSSocket.emit (events.js:208:7)
at TLSSocket._finishInit (_tls_wrap.js:637:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:467:38)
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
errorMessages: [ 'unable to verify the first certificate' ] }

I then removed the https:// from the baseURLFn but got a protocol error.

errorMessages:
[ 'Invalid protocol: 103e575486674f74bXXXXXXXXXXXXXXXXXXXXXXXX.ece-playground.dev.sg:' ] }

How could the error be solved?

Hey Ong,

Do you expect that the domain where you're hosting your Enterprise Search deploy has a valid SSL cert? I would make sure this hostname is using a valid SSL cert:

103e575486674f74bXXXXXXXXXXXXXXX.ece-playground.dev.sg

If you're just testing around at a hostname with no valid cert, I'm unsure if the AppSearch client can be configured to ignore SSL validation errors.

It's possible you could configure the entire Node.js environment to ignore cert validation, but that would be insecure and I would advise against it: Command-line API | Node.js v21.2.0 Documentation.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.