coder
coder

Reputation: 393

Export Data MongoDB to ElasticSearch

I want to export data from MongoDB to ElasticSearch.Mongo River plugin is an option for me to first take dump of collection and then restore which works fine for me.But I do not want to use Mongo River plugin , I am using elaster to export data from MongoDB to Elasticsearch.

When I execute : ./bin/elaster it says:

{ 
  [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?]'
}

My Elaster Configuration is:

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'
            },
          }
        }
      }
    }
  ]
};

Also please check sample document in-line

{
  "_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
}

Upvotes: 1

Views: 2584

Answers (2)

Aroon
Aroon

Reputation: 11

WCT field is mapped as number type but one your document is having wct value as string that's why you are getting such error so try to change your wct value from string to integer.

Upvotes: 0

BatScream
BatScream

Reputation: 19700

Since you have defined "collection"as the type and your index as "walldisplay", the type in the mapping should be "collection" rather than "walldisplay".

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

See if the following works

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

Upvotes: 1

Related Questions