ExpressJs功能错误

时间:2017-11-18 03:38:54

标签: javascript node.js elasticsearch

我遵循我在线发现的Elasticsearch和ExpressJS教程,通过ExpressJS API与ES进行交互。每当我通过Postman搜索索引中的某些内容时,我都会收到此错误:

"TypeError: elasticClient.suggest is not a function at Object.getSuggestions (/node-app/search-api/elasticsearch.js:11:26)

该功能正在导出并具有正确的结束{}& ()。我错过了会导致错误的内容吗?任何提示将不胜感激

elasticsearch.js

var elasticsearch = require('elasticsearch');

const elasticClient = new elasticsearch.Client({
    host: 'localhost:9200',
    log: 'info'
});

var indexName = 'products';

function getSuggestions(input) {
    return elasticClient.suggest({
        index: indexName,
        type: 'product',
        body: {
            docsuggest: {
                text: input,
                completion: {
                    field: 'suggest',
                    fuzzy: true
                }
            }
        }
    })
}
exports.getSuggestions = getSuggestions;

route.js

var express = require('express');
var router = express.Router();

var elastic = require('../elasticsearch');

router.get('/suggest/:input', function (req, res, next) {
    elastic.getSuggestions(req.params.input).then(function (result) {
        res.json(result)
    });
});

module.exports = router;

更新 看起来这种方法并不像Jaromanda所提到的那样存在。浏览API文档以整理我需要的内容:https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/api-reference.html#api-search

0 个答案:

没有答案