nestjs / elasticsearch Goto Github PK
View Code? Open in Web Editor NEWElasticsearch module based on the official elasticsearch package 🌿
Home Page: https://nestjs.com
License: MIT License
Elasticsearch module based on the official elasticsearch package 🌿
Home Page: https://nestjs.com
License: MIT License
[ ] 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.
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.
May be we can provide forRoot or forRootAsync method in this package. that we can register ES global module easily.
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)]
};
}
Nest version: 7.4.2
For Tooling issues:
- Node version: v14.16.0
- Platform: Mac
Others:
[ ] 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.
When I pass my config for elastic like below, any elastic methods like this.elasticsearchService.search() / this.elasticsearchService.index()
transform url for connection.
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.
At call methods must be connection to localhost:9200 when I pass that url at ElasticsearchModule.registerAsync
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);
});
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:
[ ] 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.
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.
Nest version: 6.11.5
For Tooling issues:
- Node version: 10.15.2
- Platform: Linux (Debian buster)
Others:
[ ] 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.
Elasticsearch's scroll method is not available in this module
Elasticsearch's scroll method should be exposed in this module
I need to use Elasticsearch's scroll method and would like to use this module
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.
PR #727
No response
Package fails to build on Windows.
npm run build
Package builds on Windows.
No response
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.
https://gist.github.com/DmitriyIudokhin/7bff9837d05d7944f5c837923157b384
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)
Receive all query results but with recording in analytics Elasticsearch GUI
9.0.0
7.6.15
16.17.0
No response
[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)
[ ] 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.
Currently elasticsearch
is a dependency
instead of a devDependency
like other modules such as @nestjs/graphql
. I think we should do the same.
elasticsearch
should be a peer dependency and should be imported alongside of @nestjs/elasticsearch
.
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.
Nest version: X.Y.Z
For Tooling issues:
- Node version: XX
- Platform:
Others:
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)
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.
No response
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.
[ ] 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.
Currently @nestjs/elasticsearch
only supports the legacy typings of @elastic/elasticsearch
.
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
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"
});
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.
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)
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
})
[ ] Regression
[ ] Bug report
[*] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Please, pass through getSource method
https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-getsource
[ ] 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.
Currently, the elasticsearch module utilizes the legacy version of elasticsearch client library.
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.
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?
https://github.com/febouge/elastic-nest-issue
npm i
npm run start
the server should running.
9.1.4
9.1.4
16.17.1
such all.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.circleci/config.yml
cimg/node 20.11
package.json
@commitlint/cli 19.2.2
@commitlint/config-angular 19.2.2
@elastic/elasticsearch 8.13.1
@nestjs/common 10.3.7
@types/node 20.12.7
@typescript-eslint/eslint-plugin 7.7.0
@typescript-eslint/parser 7.7.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.2.0
rimraf 5.0.5
rxjs 7.8.1
typescript 5.4.5
@elastic/elasticsearch ^7.4.0 || ^8.0.0
@nestjs/common ^8.0.0 || ^9.0.0 || ^10.0.0
rxjs ^7.2.0
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
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?
https://github.com/febouge/elastic-nest-issue
The ElasticsearchService should init properly with the module options.
8.1.0
8.4.4
14.17.6
No response
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)
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 & {
~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
https://github.com/Yeboster/elasticsearch-nestjs-type-errors-example
yarn install && yarn nest start --watch
It should work without any type errors
8.0.0
7.0.0
v16.14.0
No response
[ ] 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.
fieldCaps is not exported
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.
Nest version: X.Y.Z
For Tooling issues:
- Node version: XX
- Platform:
Others:
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.
https://gist.github.com/OttlikG/3f68fcc8ef5357200ffdbaf5f6d46a95
Generate a nest project.
Change the file from the gist accordingly.
Start a single node cluser with docker
I expect to get the same stored result as I get from https://localhost:9200/ad-book/_search
9.0.0
9.3.3
16.17.1
No response
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,
.....
when I curl -X GET "http://localhost:9200"
curl: (7) Failed to connect to localhost port 9200: Connection refused
"@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",
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.