src/provider/elastic/elastic.service.ts
Methods |
|
constructor(elasticsearchService: ElasticsearchService)
|
||||||
|
Defined in src/provider/elastic/elastic.service.ts:4
|
||||||
|
Parameters :
|
| Public Async deleteDocument | ||||||
deleteDocument(indexData: any)
|
||||||
|
Defined in src/provider/elastic/elastic.service.ts:79
|
||||||
|
Parameters :
Returns :
Promise<any>
|
| Public Async deleteIndex | ||||||
deleteIndex(indexData: any)
|
||||||
|
Defined in src/provider/elastic/elastic.service.ts:70
|
||||||
|
Parameters :
Returns :
Promise<any>
|
| Public Async get | ||||||
get(searchData: any)
|
||||||
|
Defined in src/provider/elastic/elastic.service.ts:57
|
||||||
|
Parameters :
Returns :
Promise<any>
|
| Public Async insertIndex | ||||||
insertIndex(buldData: any)
|
||||||
|
Defined in src/provider/elastic/elastic.service.ts:8
|
||||||
|
Parameters :
Returns :
Promise<any>
|
| Public Async searchIndex | ||||||
searchIndex(searchData: any)
|
||||||
|
Defined in src/provider/elastic/elastic.service.ts:43
|
||||||
|
Parameters :
Returns :
Promise<any>
|
| Public Async updateByQuery |
updateByQuery(index: any, query: any, update: any)
|
|
Defined in src/provider/elastic/elastic.service.ts:26
|
|
Returns :
Promise<any>
|
| Public Async updateIndex | ||||||
updateIndex(updateData: any)
|
||||||
|
Defined in src/provider/elastic/elastic.service.ts:17
|
||||||
|
Parameters :
Returns :
Promise<any>
|
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { ElasticsearchService } from '@nestjs/elasticsearch';
@Injectable()
export class ElasticService {
constructor(private readonly elasticsearchService: ElasticsearchService) {}
public async insertIndex(buldData: any): Promise<any> {
try {
return await this.elasticsearchService.bulk(buldData);
} catch (error) {
throw new Error('Erro bulk');
}
}
public async updateIndex(updateData: any): Promise<any> {
return await this.elasticsearchService
.update(updateData)
.then((res) => res)
.catch((err) => {
throw new HttpException(err, HttpStatus.INTERNAL_SERVER_ERROR);
});
}
public async updateByQuery(index: any, query: any, update: any): Promise<any> {
return await this.elasticsearchService
.updateByQuery({
index,
body: {
query,
script: {
source: update
},
},
})
.then((res) => res)
.catch((err) => {
throw new HttpException(err, HttpStatus.INTERNAL_SERVER_ERROR);
});
}
public async searchIndex(searchData: any): Promise<any> {
return await this.elasticsearchService
.search(searchData)
// .then((res) => {
// return res.body.hits.hits.map((hit) => {
// hit._source.id = hit._id;
// return hit._source
// });
// })
.catch((err) => {
throw new HttpException(err, HttpStatus.INTERNAL_SERVER_ERROR);
});
}
public async get(searchData: any): Promise<any> {
return await this.elasticsearchService.get(searchData)
// .then((res) => {
// return res.body.hits.hits.map((hit) => {
// hit._source.id = hit._id;
// return hit._source
// });
// })
.catch((err) => {
throw new HttpException(err, HttpStatus.INTERNAL_SERVER_ERROR);
});
}
public async deleteIndex(indexData: any): Promise<any> {
return await this.elasticsearchService.indices
.delete(indexData)
.then((res) => res)
.catch((err) => {
throw new HttpException(err, HttpStatus.INTERNAL_SERVER_ERROR);
});
}
public async deleteDocument(indexData: any): Promise<any> {
return await this.elasticsearchService
.delete(indexData)
.then((res) => res)
.catch((err) => {
throw new HttpException(err, HttpStatus.INTERNAL_SERVER_ERROR);
});
}
}