I have integrated Elasticsearch (Version 5.5) into Gitlab and try to use it. This is the command I send from an external windows client:
curl -XGET gitlab.server:9200/ -H 'Content-Type: application/json' -d '{"query": {"simple_query_string" : {"fields" : ["content"], "query" : "foo bar -baz"}}}'
but it doesn't work. On the client I get these errors:
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
curl: (6) Could not resolve host: text
curl: (3) [globbing] unmatched brace in column 1
curl: (3) Bad URL, colon is first character
curl: (3) [globbing] unmatched brace in column 1
curl: (3) Bad URL, colon is first character
curl: (3) [globbing] bad range in column 2
curl: (6) Could not resolve host: query
curl: (3) Bad URL, colon is first character
curl: (3) [globbing] unmatched close brace/bracket in column 13
On the server in /var/log/elasticsearch/elasticsearch.log I can see no log messages.
However, running the same exact command as above from the linux server gives me a response without errors:
{
"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"
}
I tried adding http.content_type.required: true
to the elasticsearch.yml, but the problem was the same. So, what am I doing wrong here? Why do I get a "Content-Type header not supported" from the Windows client? How can I solve this?
After changing the ' to " like this:
curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d "{"query": {"simple_query_string" : {"fields" : ["content"], "query" : "foo bar -baz"}}}"
I recieve this response:
{
"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
After changing the enclosing quotes from '
to "
, escape the quotation marks "
used inside the parameters as below:
curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d "{\"query\": {\"simple_query_string\" : {\"fields\" : [\"content\"], \"query\" : \"foo bar -baz\"}}}"
An alternative is to put the json into a file, and use the @
prefix for the parameters.
json.txt
{
"query": {
"simple_query_string" : {
"fields" : ["content"],
"query" : "foo bar -baz"
}
}
}
and run curl as below:
curl -XGET gitlab.server:9200/ -H "Content-Type: application/json" -d @json.txt