我一直在尝试在Elastic search(nodejs)中复制此Algolia方法,但未能成功完成,请提供任何帮助
这是我已经写过的基本搜索(弹性搜索)的摘要:
search(query, filters) {
const hits = [];
return client.search({
index: this.name,
q: query,
filters,
}).then((v) => {
v.hits.hits.forEach((value) => {
if (!value._source.id) {
value._source.id = value._id;
console.log(value._source.id, value._id);
}
hits.push(deepParseJson(value._source));
});
return { hits };
}).catch(err => err);
}
这是我想从算法转换为弹性搜索的汇总方法:
aggregated(query, user = '', distinct = false, active = false, tolerance = true) {
return new Promise((resolve, reject) => {
const facetfilter = active ? `[["active:${distinct}"]]` : [];
this.indexer.setSettings({
attributeForDistinct: `${user}`,
});
this.indexer.search(query, {
hitsPerPage: '10',
page: 0,
analytics: 'false',
typoTolerance: `${tolerance}`,
attributesToRetrieve: '*',
distinct: `${distinct}`,
facets: ['owner', 'country', 'targetId', 'targetID', 'artist', 'genre'],
facetFilters: facetfilter,
}, (err, content) => {
if (err != null) {
return reject(err);
}
return resolve(content);
});
});
}
我想编写聚合方法,以便它与弹性搜索(如基本搜索)一起使用。有没有人这样做,请帮助。谢谢。