1

I am trying to create an elastic search index if it doesn't exist using OnModuleInit (NestJs). It works fine with my local machine but when I am trying to deploy to AWS ES Cluster, this part is giving such an error.

ElasticsearchModule.registerAsync({
          useFactory: async () => ({
            node: process.env.ES_ENDPOINT,
            maxRetries: 3,
            requestTimeout: 60000,
            pingTimeout: 60000,
          }),
        })

    export class ClientElasticSearchModule implements OnModuleInit {
      constructor(private clientSearchService: ClientElasticSearchService) {}
      async onModuleInit() {
        await this.clientSearchService.createIndex();
      }
    }

It is where I am creating an index:

await this.elasticsearchService.indices.create({
          index: clientsIndex,
          body: {
            settings: {
              analysis: {...},
            },
            mappings: {
              properties: {
                name: {
                  type: 'text',
                  fields: {
                    complete: {
                      type: 'text',
                      analyzer: 'autocomplete_analyzer',
                      search_analyzer: 'autocomplete_search_analyzer',
                    },
                  },
                },
              },
            },
          },
        }); 

Error message:

ResponseError: Response Error
    at onBody (/code/node_modules/@elastic/elasticsearch/lib/Transport.js:337:23)
    at IncomingMessage.onEnd (/code/node_modules/@elastic/elasticsearch/lib/Transport.js:264:11)
    at IncomingMessage.emit (node:events:402:35)
    at IncomingMessage.emit (node:domain:475:12)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
      meta: {
        body: '',
        statusCode: 403,
        headers: {
          date: 'Fri, 14 Jan 2022 16:18:46 GMT',
          'content-type': 'application/json',
          'content-length': '73',
          connection: 'keep-alive',
          'x-amzn-requestid': '8b3cded2-f210-4c79-ab48-ff517725a1e2',
          'access-control-allow-origin': '*'
        },
        meta: {
          context: null,
          request: [Object],
          name: 'elasticsearch-js',
          connection: [Object],
          attempts: 0,
          aborted: false
        }
      }
    }
1
  • Can you share the error message you can get from the ES server logs? Commented Jan 15, 2022 at 6:34

1 Answer 1

1

This looks like your AWS Opensearch (same tech under the hood of Elasticsearch) instance is returning a 403. This might mean you need to set up IAM Roles and the correct access for your instance. Please See the AWS Docs

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

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.