我不确定,如何在角度应用程序中使用下面链接中提供的elasticsearch API。
https://www.elastic.co/guide/en/elasticsearch/reference/current/search.html
我已经通过以下方式使用弹性搜索服务。但对于其他功能,如多字段搜索,条件搜索,第一页和最后一页的分页,我不知道如何继续。
请在角度cli(角度2)应用中使用弹性搜索分享任何链接或指导我。
还有一个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)=> {})