elastisch icon indicating copy to clipboard operation
elastisch copied to clipboard

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

Open qleguennec opened this issue 5 years ago • 1 comments

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.

qleguennec avatar Sep 07 '18 09:09 qleguennec

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

firthh avatar Oct 08 '18 13:10 firthh