ElasticSearch :content-type header application/x-www-form-urlencoded is not supported - elasticsearch

So i had this error after typing this command:
curl -XPUT localhost:9200/_bulk --data-binary #movies_elastic.json, i found an answer here : ElasticSearch - Content-Type header [application/x-www-form-urlencoded] is not supported
that suggested to add -H option but i didn't get where to add it exactly.
Please keep in mind i'm new to ELK.
Thanks.
screenshot from console

Assuming everything else with your command is correct, it's a command line option to curl. Like this:
curl -XPUT localhost:9200/_bulk -H'Content-Type: application/json' --data-binary #movies_elastic.json

Related

Unable to send bulk request to Elasticsearch cloud

I am trying to send bulk request to Elasticsearch cloud with following curl string -
curl -u myusername:mypassword -H "Content-Type: application/x-ndjson" -XPOST https://el.kb.us-east-2.aws.elastic-cloud.com/products/_bulk --data-binary "products-bulk.json"
I am getting the following error -
{"statusCode":404,"error":"Not Found","message":"Not Found"}
Can someone please help me with the issue ?
I think you're using the wrong URL, you're using the Kibana URL while you should be using the ES one
https://el.kb.us-east-2.aws.elastic-cloud.com
^^
||
Should be
https://el.es.us-east-2.aws.elastic-cloud.com
^^
||

Soap wsa:To specification at curl command line

How can I compose a curl command line that contains a wsa:To Soap specification for example http://myserver.services.com/Services/ServiceUsers.svc?wsdl?
Well, in the end this is not what I wanted but I managed to achieve my goal. The solution was to use the --data argument followed by the xml request corresponding to the request and in it put the wsa:To header. By example:
curl --location --request POST 'http://myserver.services.com/Services/ServiceUsers.svc' --header 'Content-Type: application/soap+xml; charset=UTF-8' --data '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tem="http://tempuri.org/"><soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Action>http://tempuri.org/IServiceUsers/UsersList</wsa:Action><wsa:To>http://myserver.services.com/Services/ServiceUsers.svc</wsa:To></soap:Header><soap:Body><tem:UsersList/></soap:Body></soap:Envelope>'
Thanks to #DingPeng for his help, you may be right about the availability of the .Net framework

1000 max shards reached. I would like to increase or clear exisitng and start again. I have 5 servers I am monitoring

I tried to increase the shards with this...but to no avail.
curl -XPUT 'http://206.189.196.214:9200/_cluster/settings -H 'Content-type: application/json' --data-binary $'{"transient":{"cluster.max_shards_per_node":5100}}'`
I have a typo in the above ... it returned the below error:
"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"invalid
version format: -H CONTENT-TYPE:
HTTP/1.1"}],"type":"illegal_argument_exception","reason":"invalid
version format: -H CONTENT-TYPE: HTTP/1.1"},"status":400}curl: (3)
[globbing] nested brace in column 44
Please advise. Thoughts. Elasticsearch is running, Zabbix is running, logstash is running, all seems happy but reached a limit on 1000/1000 shards.
It would be a better option if you set this limit into your elasticserch.yml file. Because if you restart your cluster you will lose these configs. But your request would be something like this:
curl -XPUT "http://elasticsearch_host:9200/_cluster/settings" -H 'Content-Type: application/json' -d'
{
"transient": {
"cluster.routing.allocation.total_shards_per_node": 5100
}
}'

Load GeoJSON file into Apache CouchDB

I am working on Windows10 and tried to load a geojson file into my couchdb via the "curl" command and a POST request in the cmd which looks like that:
C:\Program Files\cURL\bin>curl -d #path-to-my-data\data.geojson -H "Content-type: application/json" -X POST http://127.0.0.1:5984/_utils/database.html?-dbName-
and then I get the following error:
{"error":"method_not_allowed","reason":"Only GET,HEAD allowed"}
On http://couchdb-13.readthedocs.org/en/latest/api-basics/ it is said, that "If you use the an unsupported HTTP request type with a URL that does not support the specified type, a 405 error will be returned, listing the supported HTTP methods."
When I try that with a PUT request, I get the same error.
I validated the json with jsonlint so this should not be the problem.
I tried several tutorials like "Three Steps to CouchDB Heaven …" or "Export & Import a Database with CouchDB" but none of them seems to work.
So I am not sure, where the problem is. Do I need to make changes in my geojson file, or something else?
thanks for your help
The needed curl command just looks like that:
curl -H "Content-Type: application/json" -X POST http://localhost:5984/db -d #C:\Users\Name\Desktop\data.geojson

How to update a TeamCity build parameter using REST+cURL

I have a configuration parameter called "testing" in one of my build configurations in TeamCity. After taking a look at the TeamCity REST API doc here I could get information about this parameter using the following cURL command line commands on Windows:
(1) curl -X GET -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters
(2) curl -X GET -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
Response:
(1) <?xml version="1.0" encoding="UTF-8" standalone="yes"?><property name="testing" value="11"/></properties>
(2) 11
But then, when I try to update this "testing" build parameter using the following command, I get an error message:
curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
Response:
Error has occurred during request processing (Unsupported Media Type).
Error: javax.ws.rs.WebApplicationException
Not supported request. Please check URL, HTTP method and transfered data are correct.
I already successfully use a similar command to update the buildNumberCounter setting of the same build configuration:
curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/settings/buildNumberCounter
That's why I thought I can do the same with a build parameter in a similar way. What am I missing here?
UPDATE:
I managed to update the "testing" build parameter with value "1" using Fiddler. The request I composed had the following content:
Request: PUT
URL: http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
Request headers: Authorization: Basic (...)
Request body: 1
So the problem with my cURL command above is probably somewhere around the -d "1" option. But where?
UPDATE 2:
I'm not sure if that makes any difference, but I use this cURL build on Windows 7.
Instead of fixing the failing cURL command, as a workaround, we use now Node.js to compose and send the REST request to TeamCity.
The script that needs to be fed to node.exe is as follows:
// Equivalent cURL command:
// curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
var http = require('http'),
options = {
hostname: 'teamcity',
port: 8080,
path: '/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing',
method: 'PUT',
headers: { 'Authorization': 'Basic (...)' }
},
req;
req = http.request(options, function(res) { });
// write data to request body
req.write('1');
req.end();
Although the workaround works perfectly, I would still like to know what's wrong with the above cURL command?
For parameters that are non-XML like the one you are asking about, just add:
--Header "Content-Type: text/plain"
For parameters that are XML then you'll want to switch that to:
--Header "Content-Type: application/xml"
I was having a hard time figuring this out too but I found the answer. Instead of using -d and -H at the front. Use --data and --header at the end as shown below . I found this in the TeamCity docs buried in a "click to expand" example.
Set build number counter:
curl -v --basic --user <username>:<password> --request PUT http://<teamcity.url>/app/rest/buildTypes/<buildTypeLocator>/settings/buildNumberCounter --data <new number> --header "Content-Type: text/plain"
Set build number format:
curl -v --basic --user <username>:<password> --request PUT http://<teamcity.url>/app/rest/buildTypes/<buildTypeLocator>/settings/buildNumberPattern --data <new format> --header "Content-Type: text/plain"
I guess the REST API expect XML as input, add
-H "Content-type:text/xml"
and put XML as input. If you have a XML file file.xml :
curl -d "#/path/to/file.xml" -H "Content-type:text/xml" (...)

Resources