Skip to content

Elasticseach singleton got error #127

@PhanSon95

Description

@PhanSon95

Hey guy
I try to using dbclient with nodejs and I got error :

Error: Do not reuse objects to configure the elasticsearch Client class: https://github.com/elasticsearch/elasticsearch-js/issues/33
    at new Client (/home/ubuntu/pelias-address-new/pelias-address/node_modules/elasticsearch/src/lib/client.js:38:11)
    at module.exports (/home/ubuntu/pelias-address-new/pelias-address/node_modules/pelias-dbclient/src/client.js:7:10)
    at streamFactory (/home/ubuntu/pelias-address-new/pelias-address/node_modules/pelias-dbclient/src/sink.js:7:56)
    at Object.createFullImportPipeline [as create] (/home/ubuntu/pelias-address-new/pelias-address/src/lib/importPipeline.ts:33:13)
    at AddressService.importToPelias (/home/ubuntu/pelias-address-new/pelias-address/src/address/address.service.ts:23:34)
    at AddressService.create (/home/ubuntu/pelias-address-new/pelias-address/src/address/address.service.ts:18:16)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

The root cause is using singleton for elasicsearch.
I reaseach and see it fixed a long time ago : #77
And it seem already merger at singleton

Now I still get this error.
This is my code using:

import * as model from 'pelias-model';
import * as peliasDbclient from 'pelias-dbclient';
import { Readable } from 'stream';
import * as combinedStream from 'combined-stream';
import { createDocumentStream } from './streams/documentStream';

function createFullImportPipeline(
  dataArray: any[],
  importerName: string,
): Readable {
    const recordStream = combinedStream.create();
    const stats = { badRecordCount: 0, goodRecordCount: 0 };

    dataArray.forEach((data) => {
      const documentStream = createDocumentStream(data, stats);
      const dataStream = new Readable({
        objectMode: true,
        read() {
          this.push(documentStream);
          this.push(null);
        },
      });
      recordStream.append(dataStream);
    });

  try {
    const pipeline = recordStream
      .pipe(model.createDocumentMapperStream())
      .pipe(peliasDbclient({ name: importerName }));

    return pipeline;
  } catch (e) {
    console.log("[createFullImportPipeline] erorr : ", e)
    throw e;
  }
  return null;
}

package json info:

    "pelias-config": "^5.2.0",
    "pelias-dbclient": "^2.15.0",
    "pelias-logger": "^1.6.0",
    "pelias-model": "^9.4.0",

** expected
for every equest, I call function createFullImportPipeline and it working fine

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions