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

Elasticseach singleton got error #127

Open
PhanSon95 opened this issue Aug 29, 2023 · 1 comment
Open

Elasticseach singleton got error #127

PhanSon95 opened this issue Aug 29, 2023 · 1 comment
Labels

Comments

@PhanSon95
Copy link

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

@PhanSon95 PhanSon95 added the bug label Aug 29, 2023
@SkyTik
Copy link

SkyTik commented Oct 25, 2023

You may consider this repo https://github.com/SkyTik/pelias-dbclient-upgrade, try to pass your own client

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants