小编典典

不支持Content-Type标头[application / x-www-form-urlencoded] [重复]

elasticsearch

我已经将Elasticsearch(5.5版)集成到Gitlab中并尝试使用它。这是我从外部Windows客户端发送的命令:

curl -XGET gitlab.server:9200/ -H 'Content-Type: application/json' -d '{"query": {"simple_query_string" : {"fields" : ["content"], "query" : "foo bar -baz"}}}'

但这不起作用。在客户端上,我得到以下错误:

{“错误”:“不支持Content-Type标头[应用程序/ x-www-form-urlencoded]”,“状态”:406}
curl:(6)无法解析主机:text
curl:(3)[globbing ]第1列
curl中不匹配的花括号:(3)错误的URL,冒号是第一个字符
curl:(3)[globbing]在第1列
curl中不匹配的花括号:(3)错误的URL,冒号是第一个字符
curl:(3)[globbing ]第2列中的错误范围
curl:(6)无法解析主机:查询
curl:(3)错误的URL,冒号是第一个字符
curl:(3)[globbing]第13列中的大括号/括号不匹配

在/var/log/elasticsearch/elasticsearch.log中的服务器上,我看不到任何日志消息。

但是,从linux服务器运行与上述相同的确切命令会给我一个没有错误的响应:

{
  "name" : "name",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "uuid",
  "version" : {
    "number" : "5.5.0",
    "build_hash" : "260387d",
    "build_date" : "2017-06-30T23:16:05.735Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}

我尝试添加http.content_type.required: true到elasticsearch.yml中,但问题是相同的。那么,我在这里做错了什么?为什么从Windows客户端获取“不支持Content-
Type标头”?我该如何解决?

像这样将’更改为’之后:

curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d "{"query": {"simple_query_string" : {"fields" : ["content"], "query" : "foo bar -baz"}}}"

我收到此回复:

{
  "name" : "name",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "uuid",
  "version" : {
    "number" : "5.5.0",
    "build_hash" : "260387d",
    "build_date" : "2017-06-30T23:16:05.735Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}
curl: (6) Could not resolve host: bar

阅读 447

收藏
2020-06-22

共1个答案

小编典典

将封闭的引号从更改为后,请对参数内部使用的引号'进行"转义",如下所示:

curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d "{\"query\": {\"simple_query_string\" : {\"fields\" : [\"content\"], \"query\" : \"foo bar -baz\"}}}"

另一种选择是将json放入文件中,并使用@前缀作为参数。

json.txt

{
  "query": {
    "simple_query_string" : { 
      "fields" : ["content"], 
      "query" : "foo bar -baz"
    }
  }
}

并如下运行curl:

curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d @json.txt
2020-06-22