2014-09-03 80 views
1

我想從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 
} 

回答

1

既然你已經定義爲「收集」的類型和你的指數爲「交互演示平臺」樣本文檔,在映射的類型應爲「收集」,而不是「交互演示平臺」。

The put mapping API allows to register specific mapping definition for a specific type

看看下面的作品

.. 
    mappings:{ 
       "collection":{ 
         "properties":{ 
           ... 
          } 
        } 
       } 
+0

嗨,謝謝你的回覆。是的,它幫助我繼續前進。現在它給了我下面的錯誤{[Error:MapperParsingException [解析失敗[wct]];嵌套:NumberFormatException [用於輸入字符串:「i」]; ] message:'MapperParsingException [未解析[wct]];嵌套:NumberFormatException [用於輸入字符串:「i」]; '} 正如您在提供的文檔中看到的WCT =>整數值,「i」是一個數組。 – coder 2014-09-03 11:59:35

+0

檢查您是否已經有了名稱爲「walldisplay」的索引並在elasticsearch中使用映射鍵入「collection」。刪除映射或類型本身,然後再次嘗試加載。 – BatScream 2014-09-03 12:20:17

+0

是的,我通過curl -XDELETE'http:// localhost:9200/*/_ mapping/*'刪除所有現有的映射,並重新啓動Elastic Search.But仍然得到相同的錯誤。 – coder 2014-09-03 13:01:38

0

WCT字段映射爲數字類型,但一個文檔是有WCT值的字符串,這就是爲什麼你得到這樣的錯誤,從而試圖改變自己的WCT值從字符串到整數。