导出数据MongoDB到ElasticSearch
问题描述:
我想从MongoDB导出数据到ElasticSearch.Mongo River插件是一个选项,我首先需要转储收集然后恢复,对我来说工作正常。但我不想使用Mongo River插件,我使用elaster
将数据从MongoDB导出到Elasticsearch。导出数据MongoDB到ElasticSearch
- 弹性搜索版本 - 1.3.2
- Node.js的版本 - v0.11.8预
- MongoDB的版本 - 2.4.x的
当我执行:./bin/elaster
它说:
{
[Error: MapperParsingException[object mapping for [collection] tried to parse as object, but got EOF, has a concrete value been provided to it?]]
message: 'MapperParsingException[object mapping for [collection] tried to parse as object, but got EOF, has a concrete value been provided to it?]'
}
我Elaster配置为:
module.exports = {
mongo: {
connection: 'mongodb://127.0.0.1:27017/times'
},
elastic: {
host: {
host: '127.0.0.1'
},
requestTimeout: 5000
},
collections: [
{
name: "walldisplay",
index: "walldisplay",
type: "collection",
fields: [
"_id",
"wat",
"wct",
"u",
"i",
"cd"
],
mappings: {
"collection": {
"properties": {
"wat":{
'type':'string',
'index': 'not_analyzed'
},
"wct":{
'type':'string',
'index': 'not_analyzed'
},
"u":{
"type" : "object",
"dynamic" : true,
"properties":{
"_id":{
'type':'string',
'index': 'not_analyzed'
},
"n":{
'type':'string',
'index': 'not_analyzed'
},
"st":{
'type':'string',
'index': 'not_analyzed'
},
"id":{
'type':'string',
'index': 'not_analyzed'
}
},
"index":"not_analyzed"
},
"i":{
"type" : "nested",
"include_in_parent" : true,
"properties":{
"_id":{
'type':'string',
'index': 'not_analyzed'
},
"ti":{
'type':'string',
'index': 'not_analyzed'
},
"st":{
'type':'string',
'index': 'not_analyzed'
},
"n":{
'type':'string',
'index': 'not_analyzed'
},
"cst":{
'type':'string',
'index': 'not_analyzed'
}
}
},
"cd":{
'type':'long',
'index': 'not_analyzed'
},
}
}
}
}
]
};
同时请在线
{
"_id": ObjectId("5406a47970b17246b9a293e1"),
"cd": 1409721465,
"i": [
{
"_id": ObjectId("50f693d17deed44cf000007f"),
"st": "seo-title",
"ti": "title",
"n": "categoryname",
"cst": "category-seotitle",
"r": null,
"c": null
},
{
"_id": ObjectId("50f693d17deed44cf000007f"),
"st": "seo-title",
"ti": "title",
"n": "categoryname",
"cst": "category-seotitle",
"r": null,
"c": null
},
{
"_id": ObjectId("50f693d17deed44cf000007f"),
"st": "seo-title",
"ti": "title",
"n": "categoryname",
"cst": "category-seotitle",
"r": null,
"c": null
}
],
"u": {
"_id": ObjectId("50ce4f79edaffd69e40ee010"),
"n": "Richa Sen",
"st": "richasen",
"id": "d8mzxlp9ekn323l6jg5s8tly1"
},
"wat": 1,
"wct": 1
}
答
既然你已经定义为“收集”的类型和你的指数为“交互演示平台”样本文档,在映射的类型应为“收集”,而不是“交互演示平台”。
The put mapping API allows to register specific mapping definition for a specific type
看看下面的作品
..
mappings:{
"collection":{
"properties":{
...
}
}
}
答
WCT字段映射为数字类型,但一个文档是有WCT值的字符串,这就是为什么你得到这样的错误,从而试图改变自己的WCT值从字符串到整数。
嗨,谢谢你的回复。是的,它帮助我继续前进。现在它给了我下面的错误{[Error:MapperParsingException [解析失败[wct]];嵌套:NumberFormatException [用于输入字符串:“i”]; ] message:'MapperParsingException [未解析[wct]];嵌套:NumberFormatException [用于输入字符串:“i”]; '} 正如您在提供的文档中看到的WCT =>整数值,“i”是一个数组。 – coder 2014-09-03 11:59:35
检查您是否已经有了名称为“walldisplay”的索引并在elasticsearch中使用映射键入“collection”。删除映射或类型本身,然后再次尝试加载。 – BatScream 2014-09-03 12:20:17
是的,我通过curl -XDELETE'http:// localhost:9200/*/_ mapping/*'删除所有现有的映射,并重新启动Elastic Search.But仍然得到相同的错误。 – coder 2014-09-03 13:01:38