{"action":"created","issue":{"url":"https://api.github.com/repos/mpenet/spandex/issues/16","repository_url":"https://api.github.com/repos/mpenet/spandex","labels_url":"https://api.github.com/repos/mpenet/spandex/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/mpenet/spandex/issues/16/comments","events_url":"https://api.github.com/repos/mpenet/spandex/issues/16/events","html_url":"https://github.com/mpenet/spandex/pull/16","id":224205968,"number":16,"title":"Add leading slash to the _bulk url","user":{"login":"zudov","id":2613966,"avatar_url":"https://avatars0.githubusercontent.com/u/2613966?v=3","gravatar_id":"","url":"https://api.github.com/users/zudov","html_url":"https://github.com/zudov","followers_url":"https://api.github.com/users/zudov/followers","following_url":"https://api.github.com/users/zudov/following{/other_user}","gists_url":"https://api.github.com/users/zudov/gists{/gist_id}","starred_url":"https://api.github.com/users/zudov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zudov/subscriptions","organizations_url":"https://api.github.com/users/zudov/orgs","repos_url":"https://api.github.com/users/zudov/repos","events_url":"https://api.github.com/users/zudov/events{/privacy}","received_events_url":"https://api.github.com/users/zudov/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-04-25T16:58:36Z","updated_at":"2017-04-25T18:27:06Z","closed_at":"2017-04-25T18:23:14Z","pull_request":{"url":"https://api.github.com/repos/mpenet/spandex/pulls/16","html_url":"https://github.com/mpenet/spandex/pull/16","diff_url":"https://github.com/mpenet/spandex/pull/16.diff","patch_url":"https://github.com/mpenet/spandex/pull/16.patch"},"body":"Having a forward slash is consistent with e.g. `scroll-chan` and `utils/url`, and sometimes saves from serious troubles.\r\n\r\nI was setting up my application in AWS environment with [Amazon ElasticSearch Service](https://aws.amazon.com/elasticsearch-service/).\r\n\r\nEverything was fine, except that `bulk-chan` didn't work. When I would try to execute the code like:\r\n\r\n```clojure\r\n;; localhost:9200 is a ssh tunnel, that directs me to Amazon'ss ES cluster\r\n;; through a gateway machine.\r\n(let [es (qbits.spandex/client {:hosts [\"http://localhost:9200\"]})\r\n      {:keys [input-ch output-ch]} (qbits.spandex/bulk-chan es)\r\n      ops [{:index {:_index :test\r\n                    :_type  :test\r\n                    :_id    1}}\r\n           {}]]\r\n  (clojure.core.async/put! input-ch ops)\r\n  (clojure.core.async/go-loop []\r\n    (clojure.pprint/pprint (clojure.core.async/<!! output-ch)))\r\n  (clojure.core.async/close! input-ch))\r\n```\r\n\r\nI would get 400 BAD_REQUEST with no body:\r\n\r\n```clojure\r\n[{:type clojure.lang.ExceptionInfo\r\n  :message \"Response Exception\"\r\n  :data #qbits.spandex.Response{:body \"\", :status 400, :headers {\"Content-Length\" \"0\", \"Connection\" \"Close\"}, :hosts #object[org.apache.http.HttpHost 0x602a2cdc \"http://localhost:9200\"], :type :qbits.spandex/response-exception}}]\r\n```\r\n\r\nCapturing the requests with `ngrep` gave me the following\r\n\r\n```\r\nT *.*.*.*:**** -> *.*.*.*:**** [AP]\r\n  PUT _bulk HTTP/1.1..content-type: text/plain..Content-Length: 54..Host: localhost:9200..Connection: Keep-Alive..User-Agent: Apache-HttpAsyncClient/4.1.2 (Java/1.8.0_74)....{\"index\":{\"_index\":\"test\",\"_type\":\"test\",\"_id\":1}}.{}.\r\n\r\nT *.*.*.*:**** -> *.*.*.*:**** [AP]\r\n  HTTP/1.1 400 BAD_REQUEST..Content-Length: 0..Connection: Close....\r\n```\r\n\r\nThe same code would work just fine with a self-hosted ES.\r\nAfter long time of eyegazing and trying many different things, I realized that the problem is due to missing leading slash, which causes some pedantic AWS's proxy to reject the requests.\r\n\r\nAdding the slash fixed the problem:\r\n\r\n```\r\nT *.*.*.*:**** -> *.*.*.*:**** [AP]\r\n  PUT /_bulk HTTP/1.1..content-type: text/plain..Content-Length: 54..Host: localhost:9200..Connection: Keep-Alive..User-Agent: Apache-HttpAsyncClient/4.1.2 (Java/1.8.0_74)....{\"index\":{\"_index\":\"test\",\"_type\":\"test\",\"_id\":1}}.{}.\r\n\r\nT *.*.*.*:**** -> *.*.*.*:**** [AP]\r\n  HTTP/1.1 200 OK..Access-Control-Allow-Origin: *..Content-Type: application/json; charset=UTF-8..Content-Length: 198..Connection: keep-alive....{\"took\":9,\"errors\":false,\"items\":[{\"index\":{\"_index\":\"test\",\"_type\":\"test\",\"_id\":\"1\",\"_version\":10,\"result\":\"updated\",\"_shards\":{\"total\":2,\"successful\":2,\"failed\":0},\"created\":false,\"status\":200}}]}\r\n```"},"comment":{"url":"https://api.github.com/repos/mpenet/spandex/issues/comments/297122473","html_url":"https://github.com/mpenet/spandex/pull/16#issuecomment-297122473","issue_url":"https://api.github.com/repos/mpenet/spandex/issues/16","id":297122473,"user":{"login":"mpenet","id":106390,"avatar_url":"https://avatars0.githubusercontent.com/u/106390?v=3","gravatar_id":"","url":"https://api.github.com/users/mpenet","html_url":"https://github.com/mpenet","followers_url":"https://api.github.com/users/mpenet/followers","following_url":"https://api.github.com/users/mpenet/following{/other_user}","gists_url":"https://api.github.com/users/mpenet/gists{/gist_id}","starred_url":"https://api.github.com/users/mpenet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mpenet/subscriptions","organizations_url":"https://api.github.com/users/mpenet/orgs","repos_url":"https://api.github.com/users/mpenet/repos","events_url":"https://api.github.com/users/mpenet/events{/privacy}","received_events_url":"https://api.github.com/users/mpenet/received_events","type":"User","site_admin":false},"created_at":"2017-04-25T18:27:06Z","updated_at":"2017-04-25T18:27:06Z","body":"Using utils/url doesn't bring anything in these cases I believe. But with both scroll and bulk the user can overwrite :url and do that if for instance one wants to qualify the index at that level."}}
{"actor":{"display_login":"mpenet"}}