dakrone / es-mode

An Emacs major mode for interacting with Elasticsearch
GNU General Public License v3.0
196 stars 34 forks source link

Remove bareline from empty body #55

Closed drewr closed 7 years ago

drewr commented 7 years ago

With no payload like below, request-data ends up with \n. This causes ES to bomb trying to make sense of null as the body.

POST /_search
dakrone commented 7 years ago

I'll have to check, but I think this might break /_bulk since it requires the trailing newline?

drewr commented 7 years ago

It's a good question. It seems like it should, but I've been using the patch with bulk and it works.

dakrone commented 7 years ago

It looks like it causes the last operation to be missed with /_bulk, for instance, if I do:

POST /_bulk
{ "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_type" : "type1", "_id" : "2" } }
{ "update" : {"_id" : "1", "_type" : "type1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }

The response is

{
  "took" : 10,
  "errors" : false,
  "items" : [
    {
      "index" : {
        "_index" : "test",
        "_type" : "type1",
        "_id" : "1",
        "_version" : 13,
        "result" : "updated",
        "_shards" : {
          "total" : 2,
          "successful" : 1,
          "failed" : 0
        },
        "created" : false,
        "status" : 200
      }
    },
    {
      "delete" : {
        "found" : false,
        "_index" : "test",
        "_type" : "type1",
        "_id" : "2",
        "_version" : 13,
        "result" : "not_found",
        "_shards" : {
          "total" : 2,
          "successful" : 1,
          "failed" : 0
        },
        "status" : 404
      }
    }
  ]
}

Which shows it's missing the final operation (the update)

dakrone commented 7 years ago

Thanks @drewr!

drewr commented 7 years ago

Oh, wow, that's a good catch. I didn't even consider that possibility because I thought ES errored on a dangling line. Updated to check if we really had an empty payload and only trim... nevermind I forgot to submit the comment and you already merged 😄