简体   繁体   中英

elasticsearch.js bulk insert error

I am trying to insert/update data with the javascript elasticsearch client, but I am getting the error:

  {
    "error": {
      "root_cause": [
        {
          "type": "illegal_argument_exception",
          "reason": "Malformed action/metadata line [1], expected a simple value for field [_data] but found [START_OBJECT]"
        }
      ],
      "type": "illegal_argument_exception",
      "reason": "Malformed action/metadata line [1], expected a simple value for field [_data] but found [START_OBJECT]"
    },
    "status": 400
  }

This is the data that is being sent

esclient.bulk({
    body: [
        {
            "index":
            {
                "_index":"myindex",
                "_type":"movie",
                "_id":"1IEAEHNOIORANIT4SEOASNIE3HAETN2E...",
                "_data": 
                {
                    "title":"Title 2",
                    "description":"This should be updated with this new data.",
                    "score":1,
                    "suggest_title":"Title 2",
                    "img":"http://url.to.image/img.jpeg",
                    "genres":["Comedy"],
                    "release":"2015-01-07T23:00:00.000Z",
                    "language":"EN",
                    "provider":
                    {
                        "id":"InstaFilmFlixify",
                        "url":"http://www.InstaFilmFlixify.com/play?id=238412"
                    }
                }
            }
        }
    ]
})

It appears as this code generates the following request to ES:

 -> POST http://docker.me:9200/_bulk
  {
    "index": {
      "_index": "myindex",
      "_type": "movie",
      "_id": "1IEAEHNOIORANIT4SEOASNIE3HAETN2E...",
      "_data": {
        "title": "Title 2",
        "description": "This should be updated with this new.",
        "score": 1,
        "suggest_title": "Title 2",
        "img": "http://url.to.image/img.jpeg",
        "genres": [
          "Comedy"
        ],
        "release": "2015-01-07T23:00:00.000Z",
        "language": "EN",
        "provider": {
          "id": "InstaFilmFlixify",
          "url": "http://www.InstaFilmFlixify.com/play?id=238412"
        }
      }
    }
  }

What am I doing wrong? What is happening? Can this possibly be a bug in ES / the ES adapter.


Elasticsearch version 2.1

I haven't seen the "_data" parameter before. Where did you get the idea to use that?

Take a look at the docs for the js client .

Anyway, this should work for you:

esclient.bulk({
    body: [
        {
            "index":
            {
                "_index":"myindex",
                "_type":"movie",
                "_id":"1IEAEHNOIORANIT4SEOASNIE3HAETN2E...",
            }
        },
        {
            "title":"Title 2",
            "description":"This should be updated with this new data.",
            "score":1,
            "suggest_title":"Title 2",
            "img":"http://url.to.image/img.jpeg",
            "genres":["Comedy"],
            "release":"2015-01-07T23:00:00.000Z",
            "language":"EN",
            "provider":
            {
                "id":"InstaFilmFlixify",
                "url":"http://www.InstaFilmFlixify.com/play?id=238412"
            }
        }
    ]
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM