“error”:“Content-Type header [] is not supported”,“status”:406 When Inserting Data to Elasticsearch with Golang










0















Does anyone know how to fix this error?



I use Golang to insert data into elasticsearch, but it seems that there is no data inserted because of this error.




"error":"Content-Type header is not supported","status":406




I already set the content type. Note that I use elasticsearch 6.4.3



request, err := http.NewRequest("POST", urlSearch, bytes.NewBuffer(query))
request.Close = true
request.Header.Set("Content-Type", "application/json")


Last but not least, I use elastigo package to make requests to elasticsearch.










share|improve this question
























  • Have you tried after remove "request.Close = true" this line?

    – Swati
    Nov 15 '18 at 12:52






  • 1





    github.com/olivere/elastic is easy to use to make requests to Elasticsearch, maybe you could take a look at that instead of writing your own client

    – Vorsprung
    Nov 15 '18 at 12:59











  • The error says "Content-Type header is not supported". Have you tried not sending the Content-Type header?

    – Adrian
    Nov 15 '18 at 14:02















0















Does anyone know how to fix this error?



I use Golang to insert data into elasticsearch, but it seems that there is no data inserted because of this error.




"error":"Content-Type header is not supported","status":406




I already set the content type. Note that I use elasticsearch 6.4.3



request, err := http.NewRequest("POST", urlSearch, bytes.NewBuffer(query))
request.Close = true
request.Header.Set("Content-Type", "application/json")


Last but not least, I use elastigo package to make requests to elasticsearch.










share|improve this question
























  • Have you tried after remove "request.Close = true" this line?

    – Swati
    Nov 15 '18 at 12:52






  • 1





    github.com/olivere/elastic is easy to use to make requests to Elasticsearch, maybe you could take a look at that instead of writing your own client

    – Vorsprung
    Nov 15 '18 at 12:59











  • The error says "Content-Type header is not supported". Have you tried not sending the Content-Type header?

    – Adrian
    Nov 15 '18 at 14:02













0












0








0








Does anyone know how to fix this error?



I use Golang to insert data into elasticsearch, but it seems that there is no data inserted because of this error.




"error":"Content-Type header is not supported","status":406




I already set the content type. Note that I use elasticsearch 6.4.3



request, err := http.NewRequest("POST", urlSearch, bytes.NewBuffer(query))
request.Close = true
request.Header.Set("Content-Type", "application/json")


Last but not least, I use elastigo package to make requests to elasticsearch.










share|improve this question
















Does anyone know how to fix this error?



I use Golang to insert data into elasticsearch, but it seems that there is no data inserted because of this error.




"error":"Content-Type header is not supported","status":406




I already set the content type. Note that I use elasticsearch 6.4.3



request, err := http.NewRequest("POST", urlSearch, bytes.NewBuffer(query))
request.Close = true
request.Header.Set("Content-Type", "application/json")


Last but not least, I use elastigo package to make requests to elasticsearch.







elasticsearch go header content-type






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 14:38







JDO

















asked Nov 15 '18 at 10:42









JDOJDO

62




62












  • Have you tried after remove "request.Close = true" this line?

    – Swati
    Nov 15 '18 at 12:52






  • 1





    github.com/olivere/elastic is easy to use to make requests to Elasticsearch, maybe you could take a look at that instead of writing your own client

    – Vorsprung
    Nov 15 '18 at 12:59











  • The error says "Content-Type header is not supported". Have you tried not sending the Content-Type header?

    – Adrian
    Nov 15 '18 at 14:02

















  • Have you tried after remove "request.Close = true" this line?

    – Swati
    Nov 15 '18 at 12:52






  • 1





    github.com/olivere/elastic is easy to use to make requests to Elasticsearch, maybe you could take a look at that instead of writing your own client

    – Vorsprung
    Nov 15 '18 at 12:59











  • The error says "Content-Type header is not supported". Have you tried not sending the Content-Type header?

    – Adrian
    Nov 15 '18 at 14:02
















Have you tried after remove "request.Close = true" this line?

– Swati
Nov 15 '18 at 12:52





Have you tried after remove "request.Close = true" this line?

– Swati
Nov 15 '18 at 12:52




1




1





github.com/olivere/elastic is easy to use to make requests to Elasticsearch, maybe you could take a look at that instead of writing your own client

– Vorsprung
Nov 15 '18 at 12:59





github.com/olivere/elastic is easy to use to make requests to Elasticsearch, maybe you could take a look at that instead of writing your own client

– Vorsprung
Nov 15 '18 at 12:59













The error says "Content-Type header is not supported". Have you tried not sending the Content-Type header?

– Adrian
Nov 15 '18 at 14:02





The error says "Content-Type header is not supported". Have you tried not sending the Content-Type header?

– Adrian
Nov 15 '18 at 14:02












1 Answer
1






active

oldest

votes


















0














That's a strange response, as it suggests that this line:



request.Header.Set("Content-Type", "application/json")


Failed to add the value to the key slice. In modern go that does not happen, e.g.



data := byte(`"a":1`)
req, err := http.NewRequest("POST", "", bytes.NewBuffer(data))
if err != nil
fmt.Println(err)
return

req.Header.Set("Foo", "Bar")
fmt.Printf("%vn", req.Header)


Prints



map[Foo:[Bar]]


See go playground.



Are you using older version of Go that doesn't match that behavior? (I'm on 1.11.2 locally.)



Five suggestions:



(1) Handle the err return value from NewRequest to verify there's no problem there (see example above).



(2) Print the request Header value before send to verify it looks right at that point (see example above).



(3) Try the Add method for the Content-Type header instead of Set as an alternative:



func (h Header) Add(key, value string)


(4) Verify that you're not going through a proxy that strips header values.



(5) Verify that "application/json" is an acceptable content type for the endpoint you're hitting, as the empty value in the error response could be erroneous itself.



Good luck!






share|improve this answer

























  • Thanks for the reply, I already try your options from 1 to 3. As for no. 4, I am not sure that it has something to do with the proxy. For no.5, I don't know whether "application/json" is acceptable content type for elasticsearch. I use elasticsearch 6.4.3 where it won't accept string anymore. Instead, it uses Text to replace string as the data type. Do you have any idea?

    – JDO
    Nov 15 '18 at 19:17










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317602%2ferrorcontent-type-header-is-not-supported-status406-when-inserting%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














That's a strange response, as it suggests that this line:



request.Header.Set("Content-Type", "application/json")


Failed to add the value to the key slice. In modern go that does not happen, e.g.



data := byte(`"a":1`)
req, err := http.NewRequest("POST", "", bytes.NewBuffer(data))
if err != nil
fmt.Println(err)
return

req.Header.Set("Foo", "Bar")
fmt.Printf("%vn", req.Header)


Prints



map[Foo:[Bar]]


See go playground.



Are you using older version of Go that doesn't match that behavior? (I'm on 1.11.2 locally.)



Five suggestions:



(1) Handle the err return value from NewRequest to verify there's no problem there (see example above).



(2) Print the request Header value before send to verify it looks right at that point (see example above).



(3) Try the Add method for the Content-Type header instead of Set as an alternative:



func (h Header) Add(key, value string)


(4) Verify that you're not going through a proxy that strips header values.



(5) Verify that "application/json" is an acceptable content type for the endpoint you're hitting, as the empty value in the error response could be erroneous itself.



Good luck!






share|improve this answer

























  • Thanks for the reply, I already try your options from 1 to 3. As for no. 4, I am not sure that it has something to do with the proxy. For no.5, I don't know whether "application/json" is acceptable content type for elasticsearch. I use elasticsearch 6.4.3 where it won't accept string anymore. Instead, it uses Text to replace string as the data type. Do you have any idea?

    – JDO
    Nov 15 '18 at 19:17















0














That's a strange response, as it suggests that this line:



request.Header.Set("Content-Type", "application/json")


Failed to add the value to the key slice. In modern go that does not happen, e.g.



data := byte(`"a":1`)
req, err := http.NewRequest("POST", "", bytes.NewBuffer(data))
if err != nil
fmt.Println(err)
return

req.Header.Set("Foo", "Bar")
fmt.Printf("%vn", req.Header)


Prints



map[Foo:[Bar]]


See go playground.



Are you using older version of Go that doesn't match that behavior? (I'm on 1.11.2 locally.)



Five suggestions:



(1) Handle the err return value from NewRequest to verify there's no problem there (see example above).



(2) Print the request Header value before send to verify it looks right at that point (see example above).



(3) Try the Add method for the Content-Type header instead of Set as an alternative:



func (h Header) Add(key, value string)


(4) Verify that you're not going through a proxy that strips header values.



(5) Verify that "application/json" is an acceptable content type for the endpoint you're hitting, as the empty value in the error response could be erroneous itself.



Good luck!






share|improve this answer

























  • Thanks for the reply, I already try your options from 1 to 3. As for no. 4, I am not sure that it has something to do with the proxy. For no.5, I don't know whether "application/json" is acceptable content type for elasticsearch. I use elasticsearch 6.4.3 where it won't accept string anymore. Instead, it uses Text to replace string as the data type. Do you have any idea?

    – JDO
    Nov 15 '18 at 19:17













0












0








0







That's a strange response, as it suggests that this line:



request.Header.Set("Content-Type", "application/json")


Failed to add the value to the key slice. In modern go that does not happen, e.g.



data := byte(`"a":1`)
req, err := http.NewRequest("POST", "", bytes.NewBuffer(data))
if err != nil
fmt.Println(err)
return

req.Header.Set("Foo", "Bar")
fmt.Printf("%vn", req.Header)


Prints



map[Foo:[Bar]]


See go playground.



Are you using older version of Go that doesn't match that behavior? (I'm on 1.11.2 locally.)



Five suggestions:



(1) Handle the err return value from NewRequest to verify there's no problem there (see example above).



(2) Print the request Header value before send to verify it looks right at that point (see example above).



(3) Try the Add method for the Content-Type header instead of Set as an alternative:



func (h Header) Add(key, value string)


(4) Verify that you're not going through a proxy that strips header values.



(5) Verify that "application/json" is an acceptable content type for the endpoint you're hitting, as the empty value in the error response could be erroneous itself.



Good luck!






share|improve this answer















That's a strange response, as it suggests that this line:



request.Header.Set("Content-Type", "application/json")


Failed to add the value to the key slice. In modern go that does not happen, e.g.



data := byte(`"a":1`)
req, err := http.NewRequest("POST", "", bytes.NewBuffer(data))
if err != nil
fmt.Println(err)
return

req.Header.Set("Foo", "Bar")
fmt.Printf("%vn", req.Header)


Prints



map[Foo:[Bar]]


See go playground.



Are you using older version of Go that doesn't match that behavior? (I'm on 1.11.2 locally.)



Five suggestions:



(1) Handle the err return value from NewRequest to verify there's no problem there (see example above).



(2) Print the request Header value before send to verify it looks right at that point (see example above).



(3) Try the Add method for the Content-Type header instead of Set as an alternative:



func (h Header) Add(key, value string)


(4) Verify that you're not going through a proxy that strips header values.



(5) Verify that "application/json" is an acceptable content type for the endpoint you're hitting, as the empty value in the error response could be erroneous itself.



Good luck!







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 15 '18 at 15:59

























answered Nov 15 '18 at 15:48









jrefiorjrefior

2,003916




2,003916












  • Thanks for the reply, I already try your options from 1 to 3. As for no. 4, I am not sure that it has something to do with the proxy. For no.5, I don't know whether "application/json" is acceptable content type for elasticsearch. I use elasticsearch 6.4.3 where it won't accept string anymore. Instead, it uses Text to replace string as the data type. Do you have any idea?

    – JDO
    Nov 15 '18 at 19:17

















  • Thanks for the reply, I already try your options from 1 to 3. As for no. 4, I am not sure that it has something to do with the proxy. For no.5, I don't know whether "application/json" is acceptable content type for elasticsearch. I use elasticsearch 6.4.3 where it won't accept string anymore. Instead, it uses Text to replace string as the data type. Do you have any idea?

    – JDO
    Nov 15 '18 at 19:17
















Thanks for the reply, I already try your options from 1 to 3. As for no. 4, I am not sure that it has something to do with the proxy. For no.5, I don't know whether "application/json" is acceptable content type for elasticsearch. I use elasticsearch 6.4.3 where it won't accept string anymore. Instead, it uses Text to replace string as the data type. Do you have any idea?

– JDO
Nov 15 '18 at 19:17





Thanks for the reply, I already try your options from 1 to 3. As for no. 4, I am not sure that it has something to do with the proxy. For no.5, I don't know whether "application/json" is acceptable content type for elasticsearch. I use elasticsearch 6.4.3 where it won't accept string anymore. Instead, it uses Text to replace string as the data type. Do you have any idea?

– JDO
Nov 15 '18 at 19:17



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53317602%2ferrorcontent-type-header-is-not-supported-status406-when-inserting%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

27

Top Tejano songwriter Luis Silva dead of heart attack at 64

Category:Rhetoric