Skip to content

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

Open

Description

@qleguennec

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 "quentin.leguennec@zenika.com"
                     ::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.

Activity

  1. firthh commented on Oct 8, 2018

    @firthh

    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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions