I am trying to run this command
curl -XPUT -H "Content-Type: application/json" https://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
But this results in this error
curl: (6) Could not resolve host: http
curl: (3) unmatched close brace/bracket in URL position 5:
null}'
I got this command from here
https://stackoverflow.com/a/50609418/3259896
I'm am not yet very familiar with curl nor elasticseach, so I'm not sure how to pinpoint the error
If it makes a difference, I am using Windows.
I also tried
$ curl -X PUT -H "Content-Type: application/json" https://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
Edit2:
I tried
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
But now get this error
{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput#446f2dd5; line: 1, column: 2]"}],"type":"json_parse_exception","reason":"Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput#446f2dd5; line: 1, column: 2]"},"status":400}curl: (3) unmatched close brace/bracket in URL position 5:
null}'
^
I then tried
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d "{"index.blocks.read_only_allow_delete": null}"
And I got
{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Unexpected character ('i' (code 105)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput#696b36d3; line: 1, column: 3]"}],"type":"json_parse_exception","reason":"Unexpected character ('i' (code 105)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput#696b36d3; line: 1, column: 3]"},"status":400}
First off, in that other SO question, the ES node was a live one so its URL included https.
Your localhost ist almost certainly not going to have https so change it to http:
curl -XPUT -H "Content-Type: application/json" \
http://localhost:9200/_all/_settings \
-d '{"index.blocks.read_only_allow_delete": null}'
Other than that, everything looks okay, provided that your ES is running.
When successful, you should receive a simple message:
{"acknowledged":true}
Edit: go with
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d "{\"index.blocks.read_only_allow_delete\": null}"
Related
I have two snapshots that I want to insert into elasticsearch in path:
C:\Users\name\Downloads\book_backup\agg_example
C:\Users\name\Downloads\book_backup\search_example
which I properly listed in elasticsearch.yml
path.repo: ["C:\\Users\\olulo\\Downloads\\book_backup\\agg_example", "C:\\Users\\olulo\\Downloads\\book_backup\\search_example"]
my elasticsearch starts fine and creating a new index works too.
Now when I try to insert snapshot into my elasticsearch so I can work on it:
curl -XPUT "http://localhost:9200/movies/" -d '{"type":"fs", "settings":{"location":"C:\\Users\\name\\Downloads\\book_backup\\search_example", "compress":true}}'
It gives me:
curl: (1) Protocol "'http" not supported or disabled in libcurl
curl: (3) [globbing] unmatched brace in column 10
curl: (3) [globbing] unmatched close brace/bracket in column 14
In https://www.elastic.co/guide/en/elasticsearch/reference/5.2/modules-snapshots.html it seems like they've added a name at the end of path in location so I did
curl -XPUT "http://localhost:9200/movies/" -d '{"type":"fs", "settings":{"location":"C:\\Users\\name\\Downloads\\book_backup\\search_example\\test", "compress":true}}'
but still gives me same error.
following https://superuser.com/questions/1322567/http-not-supported-or-disabled-in-libcurl I've change everything to double quotes:
curl -XPUT "http://localhost:9200/_snapshot/javacafe" -d "{"type":"fs", "settings":{"location":"C:\\Users\\olulo\\Downloads\\book_backup\\search_example", "compress":true}}"
giving me :
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
Tried adding curl option as suggested Content-Type header [application/x-www-form-urlencoded] is not supported on Elasticsearch by
curl -XPUT "localhost:9200/_snapshot/javacafe" -H 'Content-Type: application/json' -d "{
"type":"fs",
"settings"{"location":"C:\\Users\\olulo\\Downloads\\book_backup\\search_example\\test", "compress":true}
}"
which outputs similar error with added statement at the end:
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}curl: (6) Could not resolve host: application
SOLVED : for windows you need to use backslash infront of double quotation mark inside {}:
curl -XPUT "localhost:9200/_snapshot/javacafe" -H "Content-Type: application/json" -d "{
\"type\":\"fs\",
\"settings\"{\"location\":"C:\\Users\\olulo\\Downloads\\book_backup\\search_example\\test", \"compress\":true}
}"
From my understanding windows use \ to consider " as it is. If so why not add backslash to all curl commands as well?
Try this:
curl -XPUT "localhost:9200/_snapshot/javacafe" -H 'Content-Type: application/json' -d '{
"type":"fs",
"settings" : {
"location":"C:\\Users\\olulo\\Downloads\\book_backup\\search_example\\test",
"compress":true
}
}'
i am getting the below error while executing the curl command in unix. Not sure if this is the right way to put the arguments in curl. Can you please advise on this?
curl -X POST -H Authorization:'Bearer AAEAAJ6ZNfGbzJkSuJ1o5rXLBec5Q' -H 'Content-Type: application/json' -d {"Filter": {"ClientName": "ABC","WorkflowName": "sk_lask"},"SortingName": "StartDate","SortingOrder": "Desc"} http://someaddress.com/api/status/search HTTP/1.1
error
curl: (3) [globbing] unmatched brace at pos 13
curl: (6) Could not resolve host: ABC,WorkflowName; Unknown error
curl: (3) [globbing] unmatched close brace/bracket at pos 9
curl: (6) Could not resolve host: StartDate,SortingOrder; Unknown error
curl: (3) [globbing] unmatched close brace/bracket at pos 5
You need to quote your header, payload and also remove HTTP/1.1 from end as this command:
curl -X POST -H 'Authorization: Bearer AAEAAJ6ZNfGbzJkSuJ1o5rXLBec5Q' \
-H 'Content-Type: application/json' \
-d '{"Filter": {"ClientName": "ABC","WorkflowName": "sk_lask"},"SortingName": "StartDate","SortingOrder": "Desc"}' \
'http://someaddress.com/api/status/search'
I would like to make cURL/Elasticsearch understand HTTP query parameters passed as normal strings while being url encoded by the command.
If I run this HTTP GET via cURL to submit the query to Elasticsearch:
curl \
-H 'Content-Type: application/json' \
-XGET '127.0.0.1:9200/movies/movie/_search?q=%2Byear%3A%3E1980+%2Btitle%3Astar%20wars&pretty'
Then I am able to retrieve the expected documents.
However if I run this cURL query:
curl \
-H 'Content-Type: application/json' \
--data-urlencode "pretty" \
--data-urlencode "q=+year:>1980 +title:star wars&pretty" \
-XGET '127.0.0.1:9200/movies/movie/_search'
Then I get this error:
{
"error": {
"root_cause": [{
"type": "json_parse_exception",
"reason": "Unrecognized token 'pretty': was expecting ('true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput#7856627; line: 1, column: 8]"
}],
"type": "json_parse_exception",
"reason": "Unrecognized token 'pretty': was expecting ('true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput#7856627; line: 1, column: 8]"
},
"status": 500
}
I am using:
cURL version 7.47.0 which should understand the command parameter --data-urlencode
Elasticsearch 6.3.1
--data-urlencode will send a POST and URL encode the body. You have to use -G or --get in order to send a GET request & append the data specified with --data-urlencode in the URL :
curl -G -v \
-H 'Content-Type: application/json' \
--data-urlencode "pretty=true" \
--data-urlencode "q=+year:>1980 +title:star wars" \
'127.0.0.1:9200/movies/movie/_search'
I have the following command which works well on Linux, but not on windows. I am not able to find any doc for curl syntax for windows. I experimented with the quotes .. but still not working. Can anyone help me with this command so that I can use it on Windows ( I have installed curl.exe in c drive)
curl -X POST -H "Content-Type: application/json" -H "X-Cachet-Token: secret" http://somegoodserver/api/v1/incidents -d '{"name":"Test","message":"Test message","status":"1"}'
The error I get is:
"status":400,"title":"Bad Request","detail":"The request cannot be fulfilled due to bad syntax.","meta": {"details":["The name format is invalid.","The status format is invalid.","The message format is invalid."]}}]}
Windows requires a ^ at the end of each line, double-quotes instead of single-quotes (except within json brackets), and within the json data, all the double-quotes must be escaped.
Here is an example of a GET and a POST that work on Win10 and WinXP command prompt:
curl -X GET ^
-H "authorization: Basic [your authentication string, if needed]" ^
-H "cache-control: no-cache" ^
-H "content-type: application/json" ^
-H "x-forte-auth-organization-id: org_333251" ^
"https://sandbox.forte.net/api/v3/organizations/org_333251/locations/loc_191620/customers/"
curl -X POST ^
-H "authorization: Basic [your authentication string, if needed]" ^
-H "cache-control: no-cache" ^
-H "content-type: application/json" ^
-H "x-forte-auth-organization-id: org_333251" ^
-d "{ \"action\": \"sale\", \"authorization_amount\": 16.99, \"billing_address\": { \"first_name\": \"Paul\", \"last_name\": \"Hurst\" }, \"card\": { \"card_type\": \"visa\", \"name_on_card\": \"Forte James\", \"account_number\": \"4111111111111111\", \"expire_month\": \"12\", \"expire_year\": \"2020\", \"card_verification_value\": \"123\" } }" ^
"https://sandbox.forte.net/api/v3/organizations/org_333251/locations/loc_191620/transactions" ^
hello I have this script in bash:
first part : authentication against server - works fine.
second part: adds user - and this works fine when I define user directly in curl code - but when I want to add user from parameters.. then I got a message error:
"{"code":400,"reason":"Bad Request","message":"The request could not
be processed because the provided content is not valid
JSON","detail":"Unexpected character ('$' (code 36)): expected a valid
value (number, String, array, object, 'true', 'false' or 'null')\n at
[Source: org.apache.catalina.connector.CoyoteInputStream#3a248e6a;
line: 2, column: 18]"}"
Any ideas how can I pass values to this script ? :)
Regards
#!/bin/bash
adm_user="admin"
adm_pass="secret"
user_name=""
user_pass=""
auth_url="http://url/OpenAM-11.0.0/json/authenticate"
add_user_url="http://url/OpenAM-11.0.0/json/users/?_action=create"
session_id=$(curl \
--request POST --header "X-OpenAM-Username: $adm_user " \
--header "X-OpenAM-Password: $adm_pass" \
--header "Content-Type: application/json" \
--data "{}" $auth_url | cut -d"\"" -f4 )
sleep 1
curl \
--request POST \
--header "iplanetDirectoryPro: $session_id" \
--header "Content-Type: application/json" \
--data \
'{
"username": "$1",
"userpassword": "secret12",
"mail": "bjensen#example.com"
}' \
$add_user_url
OK, mates I got the answer:
'{
"username": "'"$1"'",
"userpassword": "'"$2"'" ,
"mail": "bjensen#example.com"
}' \