将文档索引到Elasticearch中

5q4ezhmt  于 2022-10-06  发布在  ElasticSearch
关注(0)|答案(2)|浏览(147)

我正在尝试使用ElasticSearch https://www.elastic.co/guide/en/cloud/current/ec-working-with-elasticsearch.html中的以下命令来索引一些数据:

CURL-u用户:密码https://localhost:9200/my_index/_doc-XPOST-k‘内容类型:应用程序/json’-d‘{“标题”:“一”,“标签”:[“Ruby”]}’

但我收到错误:{“Error”:“Content-Type Header[应用程序/x-www-form-urlencode]不受支持”,“Status”:406}cURL:(3)URL格式错误/非法或缺少URL

谁能告诉我我做错了什么,或者告诉我如何做索引。

sg3maiej

sg3maiej1#

需要使用-H而不是-k传递Content-Type标头

curl -u USER:Password https://localhost:9200/my_index/_doc -XPOST -k -H 'Content-Type: application/json' -d '{ "title": "One", "tags": ["ruby"] }'
                                                                     ^^
                                                                     ||

其他的都很好

hkmswyz6

hkmswyz62#

不带“-u”标志重试,因为您已经在URL中通知了用户。

相关问题