Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP client should be configured to use {:content-type :json} by default #265

Open
qleguennec opened this issue Sep 7, 2018 · 1 comment

Comments

@qleguennec
Copy link

When executing the following snippet:

(ns zenika-elastitsch.core
  (:require
   [clojurewerkz.elastisch.rest :as esr]
   [clojurewerkz.elastisch.rest.index :as esi]
   [clojurewerkz.elastisch.rest.document :as esd]
   [clojure.spec.alpha :as spec]
   [clojure.spec.gen.alpha :as gen]))

(spec/def ::first-name string?) 
(spec/def ::last-name string?)
(spec/def ::age (spec/and int? #(> % 0)))
(spec/def ::email string?)
(spec/def ::skill #{:react :node :elasticsearch :clojure})
(spec/def ::skills (spec/coll-of ::skill :into #{}))

(spec/def ::person (spec/keys :req [::first-name ::last-name ::age ::email]
                              :opt [::skills]))

(def person-example {::first-name "Quentin"
                     ::last-name "Le Guennec"
                     ::age 24
                     ::email "[email protected]"
                     ::skills '(:react :clojure :elasticsearch)})
(spec/explain ::person 
              person-example)

(def conn (esr/connect "http://localhost:9200"))
(def mappings {"person" {:properties {:first-name {:type "string"}
                                      :last-name {:type "string"}
                                      :age {:type "integer"}
                                      :email {:type "string"}
                                      :skills {:type "array"}}}})

(esi/create conn "zenika" :mappings mappings)
(esd/create conn "zenika" "person" person-example)

I'm getting this error:

Unhandled clojure.lang.ExceptionInfo
   clj-http: status 406
   {:status 406,
    :headers
    {"content-type" "application/json; charset=UTF-8",
     "content-length" "112"},
    :body
    "{\"error\":\"Content-Type header [text/plain; charset=UTF-8] is not supported\",\"status\":406}",
    :request-time 36,
    :trace-redirects ["http://localhost:9200/zenika/person"],
    :orig-content-encoding "gzip"}

How to solve this? Thanks.

@firthh
Copy link

firthh commented Oct 8, 2018

We ran into the same issue, if you replace:

(def conn (esr/connect "http://localhost:9200"))

with

(def conn (esr/connect "http://localhost:9200" {:content-type :json}))

we found it solves the problem for us

@michaelklishin michaelklishin changed the title [text/plain; charset=UTF-8] is not supported HTTP client should be configured to use {:content-type :json} by default Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants