putMapping elasticsearch索引找不到exception
我只是试图使用putMapping创build一个索引,并相当肯定这是一个语法问题。 弹性客户端正在为.index和.search命令工作,所以我不相信它的设置是问题。 相反,它是我的putmapping代码的东西。 任何build议将不胜感激。 我想要做什么的一点描述。 我search了一个索引,发现它不存在。 我发现错误并testing它是否等于“index_not_found_exception”。 如果是这样,我需要创build索引。 “…”下面的所有内容都在.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
只能用于添加一个新的映射types到已经存在的索引。
用这个replace你的putMapping调用:
elastic.indices.createIndex({ index: "ppvevents", body: { mappings: { ppvObject: { properties: { name: {type: "string", index: "not_analyzed"}, hdid: {type: "integer"}, sdid: {type: "integer"} } } } }
- Elasticsearch聚合部分string,而不是全部string
- ElasticSearch JS客户端search
- 从节点请求Elasticsearch超时
- PostgreSQL与elasticsearch(保持同步) – nodeJS
- node.js:通过使用用户定义的id在elasticsearch中进行数据索引
- 有没有一种方法可以使用elasticsearch返回每个匹配字段只有一个命中?
- dynamic生成kibana iframe(短url)
- 在node.js环境中将mongodb与elasticsearch集成在一起
- 如何在使用摩卡进行集成testing时处理elasticsearch的索引时间