3

I am trying to create a Elastic search river for my MongoDB. I am using elasticsearch-mapper-attachments and elasticsearch-river-mongodb plug-ins. The issue I have is I get a complaint about java.lang.String cannot be cast to java.util.Map

Here is the index that I create:

{
    "type": "mongodb",
    "mongodb": {
        "collection": "config_files", 
        "db": "tore_dev"
    },
    "index": "config_files" 
}

Here is the command:

one@old-dash ~/river $ curl -X PUT "localhost:9200/_river/config_files/_meta" -d @create.json |  python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   220  100    84  100   136   3032   4909 --:--:-- --:--:-- --:--:--  5230
{
    "_id": "_meta", 
    "_index": "_river", 
    "_type": "config_files", 
    "_version": 1, 
    "created": true
}
one@old-dash ~/river $ 

Here is the status of it:

one@old-dash ~/river $ curl localhost:9200/_river/config_files/_status |  python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   640  100   640    0     0  30247      0 --:--:-- --:--:-- --:--:-- 33684
{
    "_id": "_status", 
    "_index": "_river", 
    "_source": {
        "error": "CreationException[Guice creation errors:\n\n1) Error injecting constructor, java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map\n  at org.elasticsearch.river.mongodb.MongoDBRiver.<init>(Unknown Source)\n  while locating org.elasticsearch.river.mongodb.MongoDBRiver\n  while locating org.elasticsearch.river.River\n\n1 error]; nested: ClassCastException[java.lang.String cannot be cast to java.util.Map]; ", 
        "node": {
            "id": "57f4LnVMSn2xDlo1Es0meQ", 
            "name": "Wicked", 
            "transport_address": "inet[/10.1.23.69:9300]"
        }
    }, 
    "_type": "config_files", 
    "_version": 1, 
    "found": true
}

1 Answer 1

1

Fixed it. I was passing a string into the index field:

    ...
    "index": "config_files" 
    ....

Instead I needed to pass an object into the index field:

{
    "type": "mongodb",
    "mongodb": {
        "collection": "config_files", 
        "db": "tore_dev"
    },
    "index": {
        "name": "mongo_index",
        "type": "config_files"
    }
}

The object is probably expressed in Elasticsearch internals as the java.util.Map, as they describe the objects:

 known in other languages as a hash, hashmap, dictionary or associative array.

So this explains the error message, java.lang.String cannot be cast to java.util.Map

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.