Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]OpenSearch Javascript Client No or Bad response #833

Closed
lijie123bes opened this issue Aug 8, 2024 · 1 comment
Closed

[BUG]OpenSearch Javascript Client No or Bad response #833

lijie123bes opened this issue Aug 8, 2024 · 1 comment
Labels
🐛 bug Something isn't working untriaged

Comments

@lijie123bes
Copy link

Describe the bug

I am trying to integrate OpenSearch Javascript Client with Serverless Node application.

I have setup the client as follows

const client = new Client({
    ...AwsSigv4Signer({
        region: AWS_REGION,
        service: 'es',
        // Example with AWS SDK V2:
        getCredentials: () =>
            new Promise((resolve, reject) => {
                // Any other method to acquire a new Credentials object can be used.
                AWS.config.getCredentials((err, credentials) => {
                    if (err) {
                        reject(err);
                    } else {
                        logger.info('credentials', credentials);
                    }
                });
            }),
    }),
    node: 'mydomain.url', // OpenSearch domain URL
});

And used as

export async function search(): Promise<any> {
    logger.info(`open search connection => ${client.transport.connectionPool.getConnection()?.status}`);
    let result;
    try {
        result = await client.search({ index: 'opensearch_dashboards_sample_data_ecommerce'});
        logger.info(`search response ${JSON.stringify(result.body).slice(0, 200)}`);
        return result.body;
    } catch (error: any) {
        logger.error('open search client error', error);
    }
    return result?.body;
}

However I am not getting logs after the await search call. open search connection logs as alive

Also when I try to connect to local OpenSearch Cluster using docker.

const client = new Client({
node: http://admin:admin@localhost:5601,
})

above same function returns error

{"body":"","statusCode":302,"headers":{"location":"/app/home","osd-name":"d2bf50a79df9","cache-control":"private, no-cache, no-store, must-revalidate","set-cookie":["security_authentication=Fe26.2**a7a9f2cd499adba847e8b7b4712a2b304ecc5f0783628c90c1394141a8cc805d*-rKqsQ7n_BAVWq0t01RLFQ*ArbJO8TFB1m_ZKSYOKKo02SgOzuC7mKz0XmfOLmiOdJ217Y1I2QGMeXBL0pcFzBcKLwn-3i-3vfomGQdewyrYS2EqN8d69oL5qBLcUSwVaLkOUGFiU5LMe_aLBcQoObQNK-GcBH4qH-mwUe4uDBYtqGtjv1VVFY6AjeNI5sCoIXxLhylIZRqw5csO4KHwMeu9tXPGlSxm-xpI9gz_Pc0Yg**67d8efb5627180bd7631dc9b1dc6d235ed4c19949c2cde277a0926bdabd12856*HbvmzN14lC8SMcTfI1R6-KVvsg3df_d9_eJs3YEB6Mo; HttpOnly; Path=/"],"content-length":"0","date":"Fri, 20 Oct 2023 07:35:16 GMT","connection":"keep-alive","keep-alive":"timeout=120"},"meta":{"context":null,"request":{"params":{"method":"GET","path":"/","body":null,"querystring":"","headers":{"user-agent":"opensearch-js/2.4.0 (darwin 21.6.0-arm64; Node.js v16.19.1)"},"timeout":30000},"options":{},"id":3},"name":"opensearch-js","connection":{"url":"http://localhost:5601/","id":"http://localhost:5601/","headers":{},"deadCount":0,"resurrectTimeout":0,"_openRequests":0,"status":"alive","roles":{"data":true,"ingest":true}},"attempts":0,"aborted":false}} 
2020-08-21 02:20:15: [error] - open search client error Response Error {"name":"**rror","meta":{"body":{"statusCode":"**04","error":"**ound","message":"**ound"},"statusCode":"**04","headers":{"osd-name":"**9df9","content-type":"**tf-8","cache-control":"**date","set-cookie":["**th=/"],"content-length":"**60","date":"** GMT","connection":"**live","keep-alive":"**=120"},"meta":{"request":{"params":{"method":"**ET","path":"**dZGN","headers":{"user-agent":"**9.1)"},"timeout":"**0000"},"id":"**4"},"name":"**h-js","connection":{"url":{"href":"**601/","origin":"**5601","protocol":"**ttp:","username":"**dmin","password":"**dmin","host":"**5601","hostname":"**host","port":"**01","pathname":"**/"},"id":"**601/","headers":{"authorization":"**aW4="},"_status":"**live","roles":{"data":"**ue","ingest":"**ue"},"agent":{"_eventsCount":"**2","defaultPort":"**80","protocol":"**ttp:","options":{"keepAlive":"**ue","keepAliveMsecs":"**00","maxSockets":"**56","maxFreeSockets":"**56","scheduling":"**fo"},"freeSockets":{"localhost":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null[{"_host":"**host","_readableState":{"highWaterMark":"**6384","flowing":"**ue","reading":"**ue","constructed":"**ue","needReadable":"**ue","autoDestroy":"**ue","defaultEncoding":"**f8","dataEmitted":"**ue"},"_eventsCount":"**6","_writableState":{"highWaterMark":"**6384","defaultEncoding":"**f8","allBuffers":"**ue","allNoop":"**ue","constructed":"**ue","autoDestroy":"**ue"},"_sockname":{"address":"**.0.1","family":"**v4","port":"**5189"},"_peername":{"address":"**.0.1","family":"**v4","port":"**01"},"bytesRead":"**18","remoteAddress":"**.0.1","remoteFamily":"**v4","remotePort":"**01","localAddress":"**.0.1","localPort":"**5189","localFamily":"**v4","_bytesDispatched":"**42","bytesWritten":"**42"}]]},"keepAliveMsecs":"**00","keepAlive":"**ue","maxSockets":"**56","maxFreeSockets":"**56","scheduling":"**fo","maxTotalSockets":"**nity","totalSocketCount":"**1"}}}},"stack":"ResponseError: Response Error\n  at onBody (/Users/abhimanyupatil/Desktop/repos/portal-backend/node_modules/@opensearch-project/opensearch/lib/Transport.js:425:23)\n  at IncomingMessage.onEnd (/Users/abhimanyupatil/Desktop/repos/portal-backend/node_modules/@opensearch-project/opensearch/lib/Transport.js:340:11)\n  at IncomingMessage.emit (node:events:525:35)\n  at IncomingMessage.emit (node:domain:489:12)\n  at endReadableNT (node:internal/streams/readable:1358:12)\n  at processTicksAndRejections (node:internal/process/task_queues:83:21)"}

Related component

Clients

To Reproduce

const client = new Client({
node: http://admin:admin@localhost:5601,
})

Expected behavior

no error

Additional Details

Plugins
Please list all plugins currently enabled.

Screenshots
If applicable, add screenshots to help explain your problem.

Host/Environment (please complete the following information):

  • OS: [e.g. iOS]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@dblock dblock transferred this issue from opensearch-project/OpenSearch Aug 12, 2024
@dblock dblock added 🐛 bug Something isn't working and removed untriaged labels Aug 12, 2024
@dblock
Copy link
Member

dblock commented Aug 12, 2024

There are 2 problems here it seems, one with serverless and another with local.

I would start with local. Make sure your server is up curl -k -v -u username:password https://localhost:9200 and then try running https://github.com/opensearch-project/opensearch-js/blob/main/samples/search.js.

For serverless, the service name is aoss, not es. I don't know what the logging problem is, but I do have a tested end-to-end working sample in https://github.com/dblock/opensearch-node-client-demo that you might want to compare your code with.

I'm going to close this here but feel free to ask more questions. A better place to get help is the public slack #clients channel. If you/we find any bugs we can definitely open them here.

@dblock dblock closed this as completed Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working untriaged
Projects
None yet
Development

No branches or pull requests

2 participants