弹性搜索api在角度2应用中

问题描述 投票:0回答:1

我不确定,如何在角度应用程序中使用下面链接中提供的elasticsearch API。

https://www.elastic.co/guide/en/elasticsearch/reference/current/search.html

我已经通过以下方式使用弹性搜索服务。但对于其他功能,如多字段搜索,条件搜索,第一页和最后一页的分页,我不知道如何继续。

http://javasampleapproach.com/frontend/angular/angular-4-elasticsearch-example-quick-start-how-to-add-elasticsearch-js#comment-3537

请在角度cli(角度2)应用中使用弹性搜索分享任何链接或指导我。

api elasticsearch logstash angular-cli
1个回答
4
投票

还有一个javascript客户端。 https://www.npmjs.com/package/elasticsearch

npm install elasticsearch --save

其类型可从sureTypes获得

npm install @types/elasticsearch --save

然后您可以直接在角度应用程序中使用

示例:创建ElasticSearch客户端

...
import { Client } from 'elasticsearch';
...
 this.esClient = new Client({
      host: 'elastic-url'
    });
...

官方客户端中的所有内容对于诸如分页,条件搜索等功能,您必须在传递之前正确构建查询。

示例查询:

{
  "query": {
    "bool": {
      "should": [
        {
          "term": {
              "param2": "HUMAN"
          }
        },{
          "match": {
            "param1": "param1"
          }
        }
      ]
    }
  }

用法示例:

 client.search({
        index: 'masterindex',
        body: {
          "size":0,
          "query": esQuery,
          "aggs": aggOBj
        }
      },(error, response)=> {})
© www.soinside.com 2019 - 2024. All rights reserved.