#Cannot read properties of undefined (reading 'cloud')

1 messages · Page 1 of 1 (latest)

median socket
#

My server doesn't get started because of Elascticsearch error: "Cannot read properties of undefined (reading 'cloud')". Anyone knows the solution? Cause i've already tried everything.

search.module.ts

@Module({
    imports: [
        ConfigModule,
        ElasticsearchModule.registerAsync({
            imports: [ConfigModule],
            useFactory: async (configService: ConfigService) => ({
                node: configService.get('ELASTICSEARCH_NODE'),
                auth: {
                    username: configService.get('ELASTICSEARCH_USERNAME'),
                    password: configService.get('ELASTICSEARCH_PASSWORD'),
                }
            }),
            inject: [ConfigService],
        }),
    ],
    exports: [ElasticsearchModule]
})
export class SearchModule {}

docker-compose.yml

  elastic:
    container_name: elastic
    image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2
    environment:
      - cluster.name=es-docker-cluster
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - elasticdata:/usr/share/elasticsearch/data
    ports:
      - "127.0.0.1:9200:9200"
    networks:
      - elastic
    env_file: ".env"
humble ravine
#

I'd suggest you to debug the value of node and auth properties

dense hedge
#

I'm gonna bet you added ElasticSearchService to a providers array somewhere

median socket
# dense hedge I'm gonna bet you added `ElasticSearchService` to a `providers` array somewhere

Thanks, but i have another problem right now: i'm getting "ConnectionError: connect ECONNREFUSED 127.0.0.1:9200" error after sending the request.
Here is the service file:

@Injectable()
export class FlightControllerService {

    private elasticsearchService
    constructor(
        @InjectModel(Device.name) private deviceModel: Model<DeviceSchemaDocument>,
        private readonly configService: ConfigService
    ) {
        this.elasticsearchService = new ElasticsearchService({
            node: configService.get('ELASTICSEARCH_NODE'),
            auth: {
                username: configService.get('ELASTICSEARCH_USERNAME'),
                password: configService.get('ELASTICSEARCH_PASSWORD'),
            }
        })
    }


    async addDevice(fcInput: FlightControllerInput) {
        const device = new this.deviceModel({
            ...fcInput,
        });


        const elastic = await this.elasticsearchService.index({
            index: 'device',
            document: device
        }, {
            id: device._id
        })
        console.log(elastic)
        return await device.save()
    }
}
median socket
# dense hedge I'm gonna bet you added `ElasticSearchService` to a `providers` array somewhere

Here is the complete docker-compose file:

version: '3.8'

services:

  server:
    container_name: server
    restart: always
    build:
      context: .
      dockerfile: Dockerfile
      target: development
    env_file: '.env'
    networks:
      - appnet
    depends_on:
      - database
      - elastic
      - mongo-express
    ports:
      - '3002:3000'
    volumes:
      - .:/usr/src/app
      - /usr/src/app/node_modules
    command: yarn run start:dev

  database:
    container_name: database
    image: mongo:latest
    restart: always
    networks:
      - appnet
    env_file: '.env'
    ports:
      - '127.0.0.1:27017:27017'
    volumes:
      - mongo_data:/data/db


  elastic:
    restart: always
    container_name: elastic
    image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2
    environment:
      - cluster.name=es-docker-cluster
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - elasticdata:/usr/share/elasticsearch/data
    ports:
      - "9200:9200"
    networks:
      - elastic


  mongo-express:
    container_name: mongo-express
    image: mongo-express:latest
    restart: always
    ports:
      - '127.0.0.1:8081:8081'
    networks:
      - appnet
    env_file: '.env'
    environment:
      ME_CONFIG_MONGODB_URL: ${ME_CONFIG_MONGODB_URL}
    links:
      - database


networks:
  appnet:
    driver: bridge
  elastic:
    driver: bridge


volumes:
  mongo_data:
    driver: local
  server:
    driver: local
  elasticdata:
    driver: local

env variables:

ELASTICSEARCH_NODE=http://127.0.0.1:9200/
ELASTICSEARCH_USERNAME=elastic_name
ELASTIC_PASSWORD=admin_password
dense hedge
#

You're running the server using docker-compose. You need to make use of the network setup by docker rather than the localhsot address. Use elastic as the host instead of 127.0.0.1 and it'll work just fine

visual lichenBOT
stoic thunder
#

I am facing same issue Error: Cannot read properties of undefined (reading 'cloud')

#

what can i do and also i am running elastic server on my local ubuntu

dense hedge
stoic thunder
#

okay thanks @dense hedge got it it is fixed now

stoic thunder
#

`import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ElasticsearchModule, ElasticsearchService } from '@nestjs/elasticsearch';

@Module({
imports: [
ConfigModule,
ElasticsearchModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
node: "https://localhost:9200/",
auth: { username:"elastic",password:"9KqSF9nfXGIMvM8tcgcj" },
maxRetries: 5,
requestTimeout: 60000,
sniffOnStart: true,
}),
inject: [ConfigService],
}),
],
providers: [
ElasticsearchService,SearchModule
],
controllers: [],
exports: [SearchModule]
})
export class SearchModule {}

============================================================================================================================================================================================================================================
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { ElasticsearchService } from '@nestjs/elasticsearch';

@Injectable()
export class SearchService {
constructor(private readonly elasticsearchService: ElasticsearchService) {}

public async insertIndex(bulkData: any): Promise<any> {
console.log("🚀 ~ SearchService ~ insertIndex ~ bulkData:", bulkData)
return await this.elasticsearchService.bulk(bulkData)
.then(res => res)
.catch(err => {
console.log(err);
throw new HttpException(err, HttpStatus.INTERNAL_SERVER_ERROR);
});
}

}`

ERROR
error: Error: Cannot read properties of undefined (reading 'cloud')
at ApplicationLogger.error (/home/saurav/unknown_arrive/unknown-arrive-be/src/common/logging/ApplicationLogger.ts:12:23)

#

NOW can help with this error i have share every thing to debug

#

@dense hedge

dense hedge
#

Take the ElasticSearchServicwe out of the providers array

stoic thunder
#

where should i put then

dense hedge
#

Don't

#

It's already there due to the import of the module

stoic thunder
#

`import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { ElasticsearchModule, ElasticsearchService } from '@nestjs/elasticsearch';

@Module({
imports: [
ConfigModule,
ElasticsearchModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
node: "https://localhost:9200/",
auth: { username:"elastic",password:"9KqSF9nfXGIMvM8tcgcj" },
maxRetries: 5,
requestTimeout: 60000,
sniffOnStart: true,
}),
inject: [ConfigService],
}),
],
providers: [],
controllers: [],
exports: [SearchModule]
})
export class SearchModule {}`

#

then also getting same error

dense hedge
#

How does the module export itself?

stoic thunder
#

i didnt understand sorry what

dense hedge
#

The SearchModule class has exports: [SearchModule]. How does that work?

#

Also, is there only one place that you've used ElasticSearchService or are there others?

stoic thunder
stoic thunder
dense hedge
#

Okay, and with this setup you still get the same error?

#

Can you provide access to your code?

stoic thunder
#

above i have share both file search service.ts and search.module.ts

dense hedge
#

That's not waht I asked though, is it?

stoic thunder
#

i am still getting the same error

#

you need whole code access

dense hedge
#

It wou,d make debnugging weasier

stoic thunder
#

is it nessary to keep docker compose file if my elastic search server is running on my local machin

dense hedge
#

That would be necessary if I'm going to run it, yes

stoic thunder
#

hello my server got started but when i am hitting the end point
i am getting this error
``

dense hedge
#

other side closed - Local: 127.0.0.1:39272, Remote: 127.0.0.1:9200

stoic thunder
#

okay

stoic thunder
#

error: ConnectionError: self-signed certificate in certificate chain at SniffingTransport.request (/home/saurav/unknown_arrive/unknown-arrive-be/node_modules/@elastic/transport/src/Transport.ts:603:17) at processTicksAndRejections (node:internal/process/task_queues:95:5) at ElasticsearchService.InfoApi [as info] (/home/saurav/unknown_arrive/unknown-arrive-be/node_modules/@elastic/elasticsearch/src/api/api/info.ts:64:10) at SearchService.insertIndex (/home/saurav/unknown_arrive/unknown-arrive-be/src/provider/elastic/search/search.service.ts:10:65) at ProductElasticIndex.insertProductDocument (/home/saurav/unknown_arrive/unknown-arrive-be/src/provider/elastic/product/product.elastic.index.ts:19:14) at ProductService.create (/home/saurav/unknown_arrive/unknown-arrive-be/src/module/catalogue/product/product.service.ts:29:17) at ProductController.create (/home/saurav/unknown_arrive/unknown-arrive-be/src/module/catalogue/product/product.controller.ts:21:14) { options: { redaction: { type: 'replace', additionalKeys: [] } }, meta: { body: undefined, statusCode: 0, headers: {}, meta: { context: null, request: [Object], name: 'elasticsearch-js', connection: [Object], attempts: 5, aborted: false }, warnings: null } }

#

please check this

dense hedge
#

Error is clearly written there: connection error self-signed certificate in certificate chain

#

More than likely, using https on localhost with a self signed cert is gonna cause this error

#

Elastic search probably has documentation on how to manage this

stoic thunder
#

but in module i have
ssl: { rejectUnauthorized: false, },

#

so this should not throw this