gpt4 book ai didi

node.js - Elasticsearch 返回 IndexMissingException

转载 作者:太空宇宙 更新时间:2023-11-03 22:15:41 26 4
gpt4 key购买 nike

我正在尝试使用elasticSearch + mongoose(即elmongo)在node.js 中实现搜索引擎。每当我尝试运行搜索 api 时,我都会得到“错误”:“IndexMissingException[[广告]缺失]”

这是代码

广告模式.js

var mongoose = require('mongoose');
var elmongo = require('elmongo');
var Schema = mongoose.Schema;


var AdSchema = new Schema({
title: String,
description: String,
category: String,
phoneNumber: { type: Number, unique: true},
photos: [{ type: String }],
created: { type: Date, default: Date.now},
price: Number,
password: String
});

AdSchema.plugin(elmongo);

module.exports = mongoose.model('Ad', AdSchema

);

api.js

   var Ad = require('../models/advertising');


module.exports = function(app, express) {

var api = express.Router();
Ad.sync(function(err) {
console.log("Check the number sync");
})

api.post('/search', function(req, res) {
Ad.search(req.body, function(err, result){
if(err) {
res.send(err);
return;
}
res.json(result);
});
});

return api;
}

我已经正确完成了所有操作,但它只是不想返回搜索结果。

最佳答案

正如错误所示,您的集群中没有名为“ads”的索引。除非您在 elasticsearch 配置中将属性“action.auto_create_index”设置为 false,否则索引会自动创建。您可以通过编程方式或通过运行curl 请求来创建索引。引用create index api.

关于node.js - Elasticsearch 返回 IndexMissingException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29724800/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com