角度6错误ReferenceError:与elasticsearch js“未定义过程”

yis*_*n11 3 javascript node.js elasticsearch angular angular6

在一切之前,我读到:

有关流程的问题1未定义

关于流程的问题2未定义

角度5问题

浏览器版本信息

所提供的信息均无济于事。我正在使用Angular 6,我想使用elasticsearch js将查询发送到elasticsearch。我安装了elasticsearch,弹性类型和弹性浏览器,如下所示:

npm install elasticsearch
npm install @types/elasticsearch
npm install elasticsearch-browser
Run Code Online (Sandbox Code Playgroud)

我尝试使用--save和--save-dev进行安装,但都没有成功。

然后,我创建了一个带有角度cli的新项目:

import { Component } from '@angular/core';
import { Client } from "elasticsearch";

@Component({
  selector: 'app-root',
  template: `
<script src="/node_modules/elasticsearch/src/elasticsearch.js"></script>
  <div class="container">
  <div class="row">
      <button type="" (click)="onSendElastic()">Click Me!</button>
  </div>
</div>`,
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  elClient: Client

  onSendElastic(){
    console.log('clicked on send elstic');
    this.connect()
    let res = this.elSearch()
    console.log(`res: ${res}`);

  }

  connect(){
    console.log('start connect...');

    this.elClient = new Client({
      host:"http://elasticIp:9200",
      log:"trace"
    })
    this.elClient.ping({
      requestTimeout:2000
    },(err)=>{
      if(err){
        console.log('err');
      }
      else{
        console.log('everything is ok');

      }
    })
  }

  elSearch(){
    console.log('start search...');

    return this.elClient.search({
      index:"elastic_index",
      type:"doc",
      body:{
        "query":{
          "term":{
            "field1":"true"
          }
        }
      }
    })
  }
}
Run Code Online (Sandbox Code Playgroud)

我添加了<script>标签是因为发现的一些答案表明了这一点,但并没有帮助。

的格式来自:https : //www.npmjs.com/package/elasticsearch。当我启动项目时,通过运行ng startnpm start,当我按下按钮时,得到:

点击发送elstic;开始连接...错误ReferenceError:“未定义进程” addOutputhttp:// localhost:4200 / vendor.js:100911:7Loghttp:// localhost:4200 / vendor.js:100749:5Transporthttp:// localhost:4200 / vendor.js:101610:27EsApiClienthttp:// localhost:4200 / vendor.js:99098:22Clienthttp:// localhost:4200 / vendor.js:99141:10connecthttp:// localhost:4200 / main.js:104:25onSendElastichttp: //localhost:4200/main.js:98:9View_AppComponent_0ng:///AppModule/AppComponent.ngfactory.js:14:23handleEventhttp://localhost:4200/vendor.js:39410:16callWithDebugContexthttp://localhost:4200/vendor .js:40503:22debugHandleEventhttp:// localhost:4200 / vendor.js:40206:12dispatchEventhttp:// localhost:4200 / vendor.js:36869:16renderEventHandlerClosurehttp:// localhost:4200 / vendor.js:37313:38decoratePreventDefaulthttp:/ /localhost:4200/vendor.js:47314:36invokeTaskhttp:

我找到了使用Elasticsearch浏览器的参考,但是安装它似乎没有任何作用。浏览器页面中的信息引用的是angularjs,而不是angular 2,因此我被卡住了。

为什么会发生此错误?怎么解决呢?

小智 6

我们发现该线程中的最后一个解决方案对我们有用:

特别:

 npm i -S process, then add this to polyfill.ts:
 import * as process from 'process';
 window['process'] = process;
Run Code Online (Sandbox Code Playgroud)


MPP*_*NBD 0

将 Elastic search 客户端更新到 15.1.1 解决了类似问题

"elasticsearch": "^15.1.1",
Run Code Online (Sandbox Code Playgroud)

请尝试这个。