Git Product home page Git Product logo

elasticsearch's People

Contributors

berger92 avatar brunnerlivio avatar caucik avatar chris72205 avatar dependabot[bot] avatar jbw avatar kamilmysliwiec avatar lhr0909 avatar micalevisk avatar mszalek avatar probil avatar renovate-bot avatar renovate[bot] avatar romanchuk avatar tony133 avatar wodcz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

elasticsearch's Issues

Type alias 'AggregationsAggregate' circularly references itself

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I cannot get to work the @elastic/elasticsearch package with multiple versions like v7.1x.0 and also the new v8.0.0 on a nestjs 7.0.0 project. It gives the following type error with or without using @nestjs/elasticsearch:

node_modules/@elastic/elasticsearch/lib/api/types.d.ts:2067:21 - error TS2456: Type alias 'AggregationsAggregate' circularly references itself.

2067 export declare type AggregationsAggregate = AggregationsCardinalityAggregate | AggregationsHdrPercentilesAggregate | AggregationsHdrPercentileRanksAggregate | AggregationsTDigestPercentilesAggregate | AggregationsTDigestPercentileRanksAggregate | AggregationsPercentilesBucketAggregate | AggregationsMedianAbsoluteDeviationAggregate | AggregationsMinAggregate | AggregationsMaxAggregate | AggregationsSumAggregate | AggregationsAvgAggregate | AggregationsWeightedAvgAggregate | AggregationsValueCountAggregate | AggregationsSimpleValueAggregate | AggregationsDerivativeAggregate | AggregationsBucketMetricValueAggregate | AggregationsStatsAggregate | AggregationsStatsBucketAggregate | AggregationsExtendedStatsAggregate | AggregationsExtendedStatsBucketAggregate | AggregationsGeoBoundsAggregate | AggregationsGeoCentroidAggregate | AggregationsHistogramAggregate | AggregationsDateHistogramAggregate | AggregationsAutoDateHistogramAggregate | AggregationsVariableWidthHistogramAggregate | AggregationsStringTermsAggregate | AggregationsLongTermsAggregate | AggregationsDoubleTermsAggregate | AggregationsUnmappedTermsAggregate | AggregationsLongRareTermsAggregate | AggregationsStringRareTermsAggregate | AggregationsUnmappedRareTermsAggregate | AggregationsMultiTermsAggregate | AggregationsMissingAggregate | AggregationsNestedAggregate | AggregationsReverseNestedAggregate | AggregationsGlobalAggregate | AggregationsFilterAggregate | AggregationsChildrenAggregate | AggregationsParentAggregate | AggregationsSamplerAggregate | AggregationsUnmappedSamplerAggregate | AggregationsGeoHashGridAggregate | AggregationsGeoTileGridAggregate | AggregationsRangeAggregate | AggregationsDateRangeAggregate | AggregationsGeoDistanceAggregate | AggregationsIpRangeAggregate | AggregationsFiltersAggregate | AggregationsAdjacencyMatrixAggregate | AggregationsSignificantLongTermsAggregate | AggregationsSignificantStringTermsAggregate | AggregationsUnmappedSignificantTermsAggregate | AggregationsCompositeAggregate | AggregationsScriptedMetricAggregate | AggregationsTopHitsAggregate | AggregationsInferenceAggregate | AggregationsStringStatsAggregate | AggregationsBoxPlotAggregate | AggregationsTopMetricsAggregate | AggregationsTTestAggregate | AggregationsRateAggregate | AggregationsCumulativeCardinalityAggregate | AggregationsMatrixStatsAggregate | AggregationsGeoLineAggregate;
                         ~~~~~~~~~~~~~~~~~~~~~

node_modules/@elastic/elasticsearch/lib/api/types.d.ts:2270:21 - error TS2456: Type alias 'AggregationsChildrenAggregate' circularly references itself.

2270 export declare type AggregationsChildrenAggregate = AggregationsChildrenAggregateKeys & {
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@elastic/elasticsearch/lib/api/types.d.ts:2415:21 - error TS2456: Type alias 'AggregationsFilterAggregate' circularly references itself.

2415 export declare type AggregationsFilterAggregate = AggregationsFilterAggregateKeys & {
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@elastic/elasticsearch/lib/api/types.d.ts:2510:21 - error TS2456: Type alias 'AggregationsGlobalAggregate' circularly references itself.

2510 export declare type AggregationsGlobalAggregate = AggregationsGlobalAggregateKeys & {
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

Minimum reproduction code

https://github.com/Yeboster/elasticsearch-nestjs-type-errors-example

Steps to reproduce

yarn install && yarn nest start --watch

Expected behavior

It should work without any type errors

Package version

8.0.0

NestJS version

7.0.0

Node.js version

v16.14.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Feature request: scroll method

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Elasticsearch's scroll method is not available in this module

Expected behavior

Elasticsearch's scroll method should be exposed in this module

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

I need to use Elasticsearch's scroll method and would like to use this module

Environment


Nest version: X.Y.Z

 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

I have implemented this here and can PR the changes if you are good with it.

Register elasticsearch forRoot

I'm submitting a feature request for registering elasticsearch as a global module.


[ ] Regression 
[ ] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

There are many modules in my nestjs project that will use the elasticsearch service. Currently, it is not supported to register elasticsearch as a global module. Each service call ES moudle must reconfigure the es service. This operation is not convenient.

Expected behavior

May be we can provide forRoot or forRootAsync method in this package. that we can register ES global module easily.

What is the motivation / use case for changing the behavior?

Is there any way to support configuring elasticsearch as a global module, which can be called in different module without reconfiguration.

Below is the optimized code related to this problem

@Module({
  providers: [ElasticsearchService],
  exports: [ElasticsearchService]
})
export class ElasticsearchModule {
  static register(options: ElasticsearchModuleOptions): DynamicModule {
    return {
      module: ElasticsearchModule,
      providers: [{ provide: ELASTICSEARCH_MODULE_OPTIONS, useValue: options }]
    };
  }

  static registerAsync(
    options: ElasticsearchModuleAsyncOptions
  ): DynamicModule {
    return {
      module: ElasticsearchModule,
      imports: options.imports || [],
      providers: [...this.createAsyncProviders(options)]
    };
  }
// add forRoot method to support global use case
  static forRoot(options: ElasticsearchModuleOptions): DynamicModule {
    return {
      global: true,
      module: ElasticsearchModule,
      providers: [{ provide: ELASTICSEARCH_MODULE_OPTIONS, useValue: options }]
    };
  }

  static forRootAsync(
    options: ElasticsearchModuleAsyncOptions
  ): DynamicModule {
    return {
      global: true,
      module: ElasticsearchModule,
      imports: options.imports || [],
      providers: [...this.createAsyncProviders(options)]
    };
  }

Environment


Nest version: 7.4.2

 
For Tooling issues:
- Node version: v14.16.0  
- Platform:  Mac

Others:

ConfigurationError: Missing node(s) option using @nestjs/elasticsearch?

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

ConfigurationError: Missing node(s) option
        at new Client (<path_to_project>/node_modules/@elastic/elasticsearch/index.js:52:13)
        at new ElasticsearchService (<path_to_project>/node_modules/@nestjs/elasticsearch/dist/elasticsearch.service.js:20:9)
        at Injector.instantiateClass (<path_to_project>/node_modules/@nestjs/core/injector/injector.js:277:19)
        at callback (<path_to_project>/node_modules/@nestjs/core/injector/injector.js:74:41)
        at process._tickCallback (internal/process/next_tick.js:68:7)
        at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
        at startup (internal/bootstrap/node.js:283:19)
        at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

This is where the ElasticsearchModule

    import { ElasticsearchService, ElasticsearchModule } from '@nestjs/elasticsearch';
    import { ElasticSearchConfigService } from 'src/common/elasticsearchConfig.service';

    @Module({
      imports: [
        .....
        ElasticsearchModule.registerAsync({
          useClass: ElasticSearchConfigService,
        }),
      ],
    })
    export class SomeModule {}

And this is the ElasticSearchConfigService:

import { Injectable } from '@nestjs/common';
import { ConfigService } from '../config/config.service';
import { ElasticsearchOptionsFactory, ElasticsearchModuleOptions } from '@nestjs/elasticsearch';

@Injectable()
export class ElasticSearchConfigService implements ElasticsearchOptionsFactory {
  constructor(private readonly configService: ConfigService) {}

  createElasticsearchOptions(): ElasticsearchModuleOptions {
    return this.configService.get('elasticsearch');
  }
}

The config service is passing the arguments correctly to the ElasticSearchConfigService, but I don't understand what happens after that. The client options are not reaching the Client constructor from @elastic/elasticsearch.

Environment


Nest version: 6.11.5

 
For Tooling issues:
- Node version: 10.15.2  
- Platform: Linux (Debian buster)  

Others:

Elasticsearch should be a peerDependency

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Currently elasticsearch is a dependency instead of a devDependency like other modules such as @nestjs/graphql. I think we should do the same.

Expected behavior

elasticsearch should be a peer dependency and should be imported alongside of @nestjs/elasticsearch.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

with elasticsearch being a peer dependency, it can always get the latest updates from upstream. The API doesn't change much so it doesn't matter.

Environment


Nest version: X.Y.Z

 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Build fails on non UNIX systems

Did you read the migration guide?

  • I have read the whole migration guide

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Potential Commit/PR that introduced the regression

PR #727

Versions

No response

Describe the regression

Package fails to build on Windows.

Minimum reproduction code

npm run build

Expected behavior

Package builds on Windows.

Other

No response

Analytics results Elastic GUI

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When i am sending query with 'search' method i dont have any query statistics in Elasticsearch appSearch.
But when i send it with axios directly to engine, Elastic records my query string and show analytics in their GUI.

Minimum reproduction code

https://gist.github.com/DmitriyIudokhin/7bff9837d05d7944f5c837923157b384

Steps to reproduce

Search function returns correct result but not records in Elastic GUI.
Elastic GUI can record query string only when request to engine:

const url = ELASTIC_SEARCH_URL + ELASTIC_SEARCH_ENGINE + '/search';
       const headers = {
           'Content-Type': 'application/json',
           'Authorization': 'Bearer search_xxxxxxxxxxxxxxx',
       };

       let aElasticQuery: iElasticQuery = {
           query: pBody.query,
           filters: pBody.filters,
           sort: pBody.sort,
           page: pBody.page
       }

       let aConfig = {
           method: 'post',
           maxBodyLength: Infinity,
           url: url,
           headers: headers,
           data: JSON.stringify(aElasticQuery)
       };

 
         let aResult = await axios.request(aConfig)

Expected behavior

Receive all query results but with recording in analytics Elasticsearch GUI

Package version

9.0.0

NestJS version

7.6.15

Node.js version

16.17.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

request timeout

connect success,but insert error

(node:39385) UnhandledPromiseRejectionWarning: Error: Request timed out
at YouzanService.trade_TradeCreate (/Users/mcee/Documents/work/xinzhouqi/scrm_nest/dist/youzan/youzan.service.js:116:19)
at processTicksAndRejections (internal/process/task_queues.js:97:5)

ConnectionError: other side closed

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

My elasticsearch listening on 9200 port. I configured the serve side @nestjs/elasticsearch with auth credentials and tls certificate. This is the configuration I have:

imports: [
    ElasticsearchModule.register({
      node: 'http://localhost:9200',
      auth: {
        username: 'elastic',
        password: 'xxx',
      },
      tls: {
        ca: fs.readFileSync('../http_ca.crt'),
        rejectUnauthorized: false,
      },
    }),
  ],

When I try to run a simple search it gives me the following error:

ConnectionError: other side closed - Local: 127.0.0.1:53971, Remote: 127.0.0.1:9200
    at SniffingTransport.request (/Users/gaborottlik/Developer/My/adstore-api/node_modules/@elastic/transport/src/Transport.ts:585:17)
    at ElasticsearchService.SearchApi [as search] (/Users/gaborottlik/Developer/My/adstore-api/node_modules/@elastic/elasticsearch/src/api/api/search.ts:85:10)
    at AppService.getHello (/Users/gaborottlik/Developer/My/adstore-api/src/app.service.ts:28:20)
    at AppController.getHello (/Users/gaborottlik/Developer/My/adstore-api/src/app.controller.ts:10:12)
    at /Users/gaborottlik/Developer/My/adstore-api/node_modules/@nestjs/core/router/router-execution-context.js:46:28
    at /Users/gaborottlik/Developer/My/adstore-api/node_modules/@nestjs/core/router/router-proxy.js:9:17

What's interesting that when I run search with the exact same config in an isolated environment without the @nestjs/elasticsearch library I get back result.

Minimum reproduction code

https://gist.github.com/OttlikG/3f68fcc8ef5357200ffdbaf5f6d46a95

Steps to reproduce

Generate a nest project.
Change the file from the gist accordingly.
Start a single node cluser with docker

Expected behavior

I expect to get the same stored result as I get from https://localhost:9200/ad-book/_search

Package version

9.0.0

NestJS version

9.3.3

Node.js version

16.17.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Support opensearch client fork

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

The team maintaining the official elasticsearch-js client decided to drop support for OSS distributions as part of a minor version bump, breaking many people's applications that may have been using an OSS version like that of AWS's managed elasticsearch service. (see elastic/elasticsearch-js#1519)

Describe the solution you'd like

While it's certainly possible to pin down the official client to a previous version, it would be great if this little library could also support the opensearch client (https://github.com/opensearch-project/opensearch-js), since as of now they appear to be drop in replacements.

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

I think many in the community will be transitioning away from the official client, if only to avoid getting caught in future political battles. Forking this library is certainly possible and is likely what I'll do if there is no interest here in supporting both clients.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
  • cimg/node 20.11
npm
package.json
  • @commitlint/cli 19.2.0
  • @commitlint/config-angular 19.1.0
  • @elastic/elasticsearch 8.12.2
  • @nestjs/common 10.3.3
  • @types/node 20.11.28
  • @typescript-eslint/eslint-plugin 7.2.0
  • @typescript-eslint/parser 7.2.0
  • eslint 8.57.0
  • eslint-config-prettier 9.1.0
  • eslint-plugin-import 2.29.1
  • husky 9.0.11
  • lint-staged 15.2.2
  • prettier 3.2.5
  • release-it 17.1.1
  • rimraf 5.0.5
  • rxjs 7.8.1
  • typescript 5.4.2
  • @elastic/elasticsearch ^7.4.0 || ^8.0.0
  • @nestjs/common ^8.0.0 || ^9.0.0 || ^10.0.0
  • rxjs ^7.2.0

  • Check this box to trigger a request for Renovate to run again on this repository

Unable to init Elasticsearch Service

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Hi,

I'm trying to use the module to connect to a self-managed Elasticsearch instance (see minimal example attached). But whenever I try to use ElasticsearchService, it seems that the ClientOptions are not being passed to the Client instance. I get the error:

ERROR [ExceptionHandler] Cannot read property 'cloud' of undefined 

thrown in

node_modules/@elastic/elasticsearch/src/client.ts:127:15

If you see the client code, the only option is that 'opts' are undefined.

I have also tried using ElasticsearchModule.register (with a static object) to discard any async configuration issue and it also failed.
The same configuration used directly on elastic Client is working fine.

So maybe the module is not providing the ClientOptions properly?

Minimum reproduction code

https://github.com/febouge/elastic-nest-issue

Steps to reproduce

  1. yarn install
  2. yarn start:dev

Expected behavior

The ElasticsearchService should init properly with the module options.

Package version

8.1.0

NestJS version

8.4.4

Node.js version

14.17.6

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Return value from search subscribe

I'm trying to do a simple search and process the result inside subscribe, but it seems that the return values and the typing does not match

.search(...).subscribe(res => {
  // according to typing I should get a SearchResponse having hits, took etc.
  // but get an array where the first element is the searchresponse and the 
  // second is the http return code
})

see picture
image

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

TypeError: Cannot read properties of undefined (reading 'cloud')

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

such as #794 ,when i start the nest application,the error show

the @794 issue opened on Apr 7, 2022,marked bug

so when will resolve this problem?

Minimum reproduction code

https://github.com/febouge/elastic-nest-issue

Steps to reproduce

npm i
npm run start

Expected behavior

the server should running.

Package version

9.1.4

NestJS version

9.1.4

Node.js version

16.17.1

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

such all.

elasticsearch transform localhost url at elasticsearch methods to different url.

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When I pass my config for elastic like below, any elastic methods like this.elasticsearchService.search() / this.elasticsearchService.index() transform url for connection.

image

connection: { url: 'http://172.27.0.3:9200/', }

Passing config.

@Module({
  imports: [
    ElasticsearchModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        node: 'http://localhost:9200',
        maxRetries: 10,
        requestTimeout: 6000,
        pingTimeout: 6000,
        sniffOnStart: true,
      }),
      inject: [ConfigService],
    }),
    ConfigModule,
  ],
  providers: [SearchService],
  exports: [SearchService],
})
export class SearchModule {

}

But, when I pass that config in ElasticsearchModule.register(), alll is ok.
Also when I change port to 9300 all also ok passing url ( because how I understand using different connecting method sniff )
And when I check ElasticsearchService, at constructor in my service, I see like url is correct.
image

Expected behavior

At call methods must be connection to localhost:9200 when I pass that url at ElasticsearchModule.registerAsync

Minimal reproduction of the problem with instructions

Pass config to elastic

@Module({
  imports: [
    ElasticsearchModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        node: 'http://localhost:9200',
        maxRetries: 10,
        requestTimeout: 6000,
        pingTimeout: 6000,
        sniffOnStart: true,
      }),
      inject: [ConfigService],
    }),
    ConfigModule,
  ],
  providers: [SearchService],
  exports: [SearchService],
})
export class SearchModule {

}

At service add service injection

constructor(
    private readonly elasticsearchService: ElasticsearchService,
  ) {

Call any elastic method in service

this.elasticsearchService.index<any>({
      index: 'my-index-000001',
      // type: '_doc', // uncomment this line if you are using Elasticsearch ≤ 6
      body: {
        character: 'Ned Stark',
        quote: 'Winter is coming.'
      }
    });

Check connection status

this.elasticsearchService.on('request', (err, meta) => {
      console.log(err);
      console.log('request', meta);
    });

Environment


Nest version: X.Y.Z
"@nestjs/common": "~7.5.5",
"@nestjs/core": "7.5.5",
"@elastic/elasticsearch": "^7.10.0",
"@nestjs/elasticsearch": "^7.1.0",
 
For Tooling issues:
- Node version: 12.6.0
- Platform:  Mac

Others:

Sample Project

I am sorry to posting this here..

Is there any sample project how to insert/read data from elasticsearch using nestjs/elaticsearch package?
I am not able to find an correct example.. Please help me.

Thanks,
Subu

Support new @elastic/elasticsearch TypeScript type definitions

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Currently @nestjs/elasticsearch only supports the legacy typings of @elastic/elasticsearch.

Expected behavior

It would be great if we could support the new type definitions without waiting for the next major version of @nestjs/elasticsearch and @elastic/elasticsearch.

The different type definitions are documented over here: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/typescript.html#typescript

Currently the client exposes two type definitions, the legacy one, which is the default and the new one, which will be the default in the next major

Minimal reproduction of the problem with instructions

The current ElasticsearchService class extends the Client class of @elastic/elasticsearch which exports the legacy type definitions. To use the new type definitions we have to import the new typings like this:

import { Client as NewClient } from '@elastic/elasticsearch/api/new'

// <snip>

export class ElasticsearchService extends NewClient {

// <snip>

This is documented over here: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/typescript.html#_how_to_migrate_to_the_new_type_definitions

But this would be a breaking change and is not an option. However, it would be great if we could provide another method to support the new type definitions in a minor release.

Of course you could always do something like this but native support would be sweet.

const result = await (this.elasticsearchService as unknown as NewClient).get({
  id: "my-id",
  index: "my-index"
});

What is the motivation / use case for changing the behavior?

The new type definition is more advanced compared to the legacy one. In the legacy type definitions you were expected to configure via generics both request and response bodies. The new type definitions comes with a complete type definition for every Elasticsearch endpoint.

It would be great if we could support the new types. I could create a pull request, but at this time I am not sure what the best solution would be. Maybe generics could be used, maybe a second ElasticsearchService class is the solution. I am open to suggestions here and would need some help or guidance from experienced Nest developers.

Error in connection to es

Error message
(node:13431) UnhandledPromiseRejectionWarning: ProductNotSupportedError: The client noticed that the server is not a supported distribution of Elasticsearch

Code:

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],
    }),

Please NOTE:
But it works version 7.1.0 and doen't work 8.0.0

Invalid URL

[Nest] 13136 - 2019-12-24 10:52:01 AM [NestFactory] Starting Nest application...
[Nest] 13136 - 2019-12-24 10:52:01 AM [InstanceLoader] TypegooseModule dependencies initialized +41ms
[Nest] 13136 - 2019-12-24 10:52:01 AM [ExceptionHandler] Invalid URL: 192.168.0.201:32001 +2ms
TypeError [ERR_INVALID_URL]: Invalid URL: 192.168.0.201:32001
at onParseError (internal/url.js:241:17)
at new URL (internal/url.js:319:5)
at getUsernameAndPassword (E:\ngchina\demo\node_modules@elastic\elasticsearch\index.js:233:38)
at getAuth (E:\ngchina\demo\node_modules@elastic\elasticsearch\index.js:224:16)
at new Client (E:\ngchina\demo\node_modules@elastic\elasticsearch\index.js:55:23)
at new ElasticsearchService (E:\ngchina\demo\node_modules@nestjs\elasticsearch\dist\elasticsearch.service.js:20:9)
at Injector.instantiateClass (E:\ngchina\demo\node_modules@nestjs\core\injector\injector.js:288:19)
at callback (E:\ngchina\demo\node_modules@nestjs\core\injector\injector.js:75:41)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

Upgrade ElasticSearch Client

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Currently, the elasticsearch module utilizes the legacy version of elasticsearch client library.

Expected behavior

New elasticsearch client; https://www.npmjs.com/package/@elastic/elasticsearch

Persistent, Keep-Alive connections.
Load balancing (with pluggable selection strategy) across all available nodes.
TypeScript support out of the box.

This includes support for streams, which can easily be transformed into observables.

curl: (7) Failed to connect to localhost port 9200: Connection refused

I'm submitting a...

[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

// .env
# Elasticsearch
ELASTICSEARCH_NODE=http://localhost:9200
ELASTICSEARCH_USERNAME=elastic
ELASTICSEARCH_PASSWORD=admin

// SearchModule

import { Module } from '@nestjs/common';
import { ElasticsearchModule } from '@nestjs/elasticsearch';
import { ConfigModule } from '../../config/config.module';
import { ConfigService } from '../../config/config.service';
import { SearchController } from './search.controller';
import { SearchService } from './search.service';
 
@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],
  controllers: [SearchController],
  providers: [SearchService],
})
export class SearchModule {}


// SearchService

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

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

  public search(options) {
    return this.elasticsearchService.search(options);
  }
}

// SearchController

export class SearchController {
  constructor(private readonly searchService: SearchService) { }

  @Get('searchs')
  // @UseGuards(AuthGuard('jwt'))
  @ApiOperation({ summary: 'ElasticSearch 搜索' })
  async searchs(@Body() body) {
    this.searchService.search({
      index: 'good-*',
      body: {
        query: { match: { message: 'myProduct' } },
        aggs: {
          top_10_states: {
            terms: { field: 'state', size: 10 }
          }
        }
      }
    })
    .then(({ body }) => {
      console.log('body', JSON.stringify(body))
      // const { hits } = body
    })
    .catch(error => console.error('error', JSON.stringify(error)))
  }
}

// main.modules.ts

@Module({
  imports: [
    TypeOrmModule.forRoot({}),
    ScheduleModule.forRoot(),
    SearchModule,
.....

Current behavior

when I curl -X GET "http://localhost:9200"

curl: (7) Failed to connect to localhost port 9200: Connection refused

package.json version

    "@nestjs/common": "^6.11.6",
    "@nestjs/core": "^6.11.6",
    "@nestjs/elasticsearch": "^7.1.0",
    "@nestjs/jwt": "^6.1.1",
    "@nestjs/platform-express": "^6.11.6",
    "@nestjs/platform-socket.io": "^6.11.6",
    "@nestjs/platform-ws": "^6",
    "@nestjs/websockets": "^6",
    "@elastic/elasticsearch": "^7.9.1",

Export also fieldCaps at the service

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

fieldCaps is not exported

Expected behavior

Need to export fieldCaps also, or even to change the esClient at ElasticsearchService to be a protected so it will be possible to extend the service.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Environment


Nest version: X.Y.Z

 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.