【发布时间】:2019-10-16 09:59:37
【问题描述】:
我正在做一个 Angular 6 项目,我在服务器上将 elasticsearch 的版本从 6 更新到 7,在将旧 API 的代码更改为使用新 API 之后,发生了这些错误,有没有人知道如何改正?
Angular 应用程序是在 Visual Studio 代码上创建的,而 elasticsearch 是在 linux 服务器上。
import { Injectable } from '@angular/core';
// import { Clientex } from 'elasticsearch-browser';
import { Client } from '@elastic/elasticsearch';
// import * as elasticsearch from 'elasticsearch-browser';
// import { concatMapTo } from 'rxjs/operators';
// import { stringify } from '@angular/core/src/render3/util';
@Injectable({
providedIn: 'root'
})
export class ElasticsearchService {
private client: Client;
// private clientex: Clientex;
constructor() {
if (!this.client) {
this.connect();
}
}
private connect() {
/*this.client = new Client(
{node: 'http://localhost:9200'}
);*/
this.client = new Client();
}
isAvailable(): Promise<any> {
return this.client.ping({
});
}
// tslint:disable-next-line:member-ordering
private queryalldocs = {
'query': {
'match_all': {}
}
};
getAllDocuments(_index, _type): any {
this.client.search({
index: _index,
body: this.queryalldocs
}, {
ignore: [404]
}, (err, { body, statusCode, headers, warnings }) => {
if (err) { console.log(err); }
});
}
getAllDocumentsByKey(_index, _type, campo, valor) {
const string = 'let match = {' + campo + ':' + valor + '}';
return this.client.search({
index: _index,
type: _type,
body: {
// tslint:disable-next-line:no-shadowed-variable
eval(string) {}
}
});
}
createDocument(value: any) {
// return this.client.index(value);
this.client.create(value);
}
}
错误:
./node_modules/@elastic/elasticsearch/lib/Connection.js 中的错误 找不到模块:错误:无法解析“http” 'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules@elastic\elasticsearch\lib'
./node_modules/@elastic/elasticsearch/lib/Connection.js 中的错误 找不到模块:错误:无法解析“https” 'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules@elastic\elasticsearch\lib'
./node_modules/@elastic/elasticsearch/lib/Transport.js 模块中的错误 未找到:错误:无法解析 'os' in 'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules@elastic\elasticsearch\lib'
./node_modules/decompress-response/index.js 中的错误模块未找到: 错误:无法解析中的“流” 'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules\decompress-response'
./node_modules/@elastic/elasticsearch/lib/Transport.js 模块中的错误 未找到:错误:无法解析“zlib” 'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules@elastic\elasticsearch\lib'
./node_modules/decompress-response/index.js 中的错误模块未找到: 错误:无法解析“zlib” 'C:\Users\ICARO\Desktop\projetos\pastas\xtr-social\node_modules\decompress-response'
【问题讨论】:
标签: angular typescript elasticsearch angular6