gpt4 book ai didi

node.js - putMapping elasticsearch索引未找到异常

转载 作者:太空宇宙 更新时间:2023-11-03 21:56:08 24 4
gpt4 key购买 nike

我只是尝试使用 putMapping 创建索引,并且相当确定这是一个语法问题。弹性客户端适用于 .index 和 .search 命令,因此我认为它的设置不是问题。相反,它与我的 putmapping 代码有关。任何建议将不胜感激。关于我正在尝试做的事情的一些描述。我搜索了一个索引,发现它不存在。我捕获错误并测试它是否等于“index_not_found_exception”。如果是这样,我需要创建索引。 “...”下面的所有内容都在 .catch 内。

"use strict";
let config = require("./config"),
soap = require("soap"),
elastic = require("elasticsearch").Client(config.routeHost);
...
if (error.body.error.type == "index_not_found_exception") {
console.log("no index");
elastic.indices.putMapping({
index: "ppvevents",
type: "ppvObject",
body: {
properties: {
name: {type: "string", index: "not_analyzed"},
hdid: {type: "integer"},
sdid: {type: "integer"}
}
}
}).then(function(response){
console.log("Response: ", response);
}).catch(function(error){
console.log("putMapping Error: ", error);
});
} else if(error.body.error.type != "index_not_found_exception") {
console.log("error: elasticsearch client search");
console.log(error);
}

控制台响应如下:

vagrant at localhost in /vagrant on master!
± node index.js
9000
no index
putMapping Error: { [Error: [index_not_found_exception] no such index, with { resource.type=index_or_alias resource.id=ppvevents index=ppvevents }]
status: 404,
displayName: 'NotFound',
message: '[index_not_found_exception] no such index, with { resource.type=index_or_alias resource.id=ppvevents index=ppvevents }',
path: '/ppvevents/_mapping/ppvObject',
query: {},
body:
{ error:
{ root_cause: [Object],
type: 'index_not_found_exception',
reason: 'no such index',
'resource.type': 'index_or_alias',
'resource.id': 'ppvevents',
index: 'ppvevents' },
status: 404 },
statusCode: 404,
response: '{"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"ppvevents","index":"ppvevents"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"ppvevents","index":"ppvevents"},"status":404}',
toString: [Function],
toJSON: [Function] }

最佳答案

如果索引不存在,putMapping()不会有帮助,你需要调用indices.create反而。 putMapping 只能用于向现有索引添加新映射类型。

将 putMapping 调用替换为:

    elastic.indices.createIndex({
index: "ppvevents",
body: {
mappings: {
ppvObject: {
properties: {
name: {type: "string", index: "not_analyzed"},
hdid: {type: "integer"},
sdid: {type: "integer"}
}
}
}
}

关于node.js - putMapping elasticsearch索引未找到异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40551691/

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