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

wak*_*aka 9 curl elasticsearch elasticsearch-5

我已将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"}}}'
Run Code Online (Sandbox Code Playgroud)

但它不起作用.在客户端我得到这些错误:

{"error":"不支持Content-Type标头[application/x-www-form-urlencoded]","status":406}
curl:(6)无法解析host:text
curl:(3)[globbing第1列
卷曲中无与伦比的支撑:(3)错误的URL,冒号是第一个字符
卷曲:(3)[globbing]第1列
卷曲中无法匹配的括号:(3)错误的URL,冒号是第一个字符
卷曲:(3)[globbing ]第2列
卷曲中的不良范围:(6)无法解析主机:查询
卷曲:(3)错误的URL,冒号是第一个字符
卷曲:(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"
}
Run Code Online (Sandbox Code Playgroud)

我尝试添加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"}}}"
Run Code Online (Sandbox Code Playgroud)

我接受了这个回复:

{
  "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
Run Code Online (Sandbox Code Playgroud)

Ble*_*ess 24

从改变封闭的报价后'",逃避引号",如下参数内使用:

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

另一种方法是将json放入文件中,并使用@参数前缀.

json.txt

{
  "query": {
    "simple_query_string" : { 
      "fields" : ["content"], 
      "query" : "foo bar -baz"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

并运行curl如下:

curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d @json.txt
Run Code Online (Sandbox Code Playgroud)