Update multiple Json with CURL POST - bash

I would like to update multiple JSON filed in the same curl POST but I am not able to make it work.
I keep getting 400.
I tried checking online but was not able to find another way. Maybe there is an easier way of doing this but I am not sure what it is. Thanks for the help
I tried the following
curl -X 'PUT' \
'http://192.168.1.256:123/api/accessories/123456789' \
-H 'accept: */*' \
-H 'Authorization: Bearer $token' \
-H 'Content-Type: application/json' \
-d '{
"characteristicType": "Saturation",
"value": "30"
}
{
"characteristicType": "On",
"value": "1"
}'
curl -X 'PUT' \
'http://192.168.1.256:123/api/accessories/123456789' \
-H 'accept: */*' \
-H 'Authorization: Bearer $token' \
-H 'Content-Type: application/json' \
-d '{
"characteristicType": "Saturation",
"value": "30"
},
{
"characteristicType": "On",
"value": "1"
}'
curl -X 'PUT' \
'http://192.168.1.256:123/api/accessories/123456789' \
-H 'accept: */*' \
-H 'Authorization: Bearer $token' \
-H 'Content-Type: application/json' \
-d '[
{
"characteristicType": "Saturation",
"value": "30"
}
{
"characteristicType": "On",
"value": "1"
}
]'

You may test what comes to the server by using a dummy nc server in localhost with an arbitrary port such as in the example below:
$ nc -l 10000
And change this IP/port in the curl command, so the first example becomes:
curl -X 'PUT' \
'localhost:10000' \
-H 'accept: */*' \
-H 'Authorization: Bearer $token' \
-H 'Content-Type: application/json' \
-d '{
"characteristicType": "Saturation",
"value": "30"
}
{
"characteristicType": "On",
"value": "1"
}'
This is what the server will received:
$ nc -l 10000
PUT / HTTP/1.1
Host: localhost:10000
User-Agent: curl/7.68.0
accept: */*
Authorization: Bearer $token
Content-Type: application/json
Content-Length: 106
{
"characteristicType": "Saturation",
"value": "30"
}
{
"characteristicType": "On",
"value": "1"
}
How the server will parse this is implementation dependent.
In curl man page, it suggests using an ampersand (&) to add multiple data payloads. This can be done by the command itself by adding -d parameter multiple times:
curl -X 'PUT' \
'localhost:10000' \
-H 'accept: */*' \
-H 'Authorization: Bearer $token' \
-H 'Content-Type: application/json' \
-d '{
"characteristicType": "Saturation",
"value": "30"
}' \
-d '{
"characteristicType": "On",
"value": "1"
}'
Very certainly your server will not like the resulting syntax in the body though considering it's json.
As an additional note, be careful with using bash variables inside quoted strings. If they are single quoted instead of double quoted, they are not expanded. You probably should use -H "Authorization: Bearer $token" instead.

Related

Receipt is not in any Chunks from RPC

I have the following transaction: 7gjmhdoPZcS5GQ5tbquEmzdoNXaVBmpTts6GidZZLzKM, which two receipts, the first of which is 4QJkVxdoc85VxnucLASBZykzygS3EiUyZ98eS1cAHa7L
Both the transaction and the receipt were executed in block 65694172. However, when using chunk via the RPC, the transaction is in one of the chunks (chunk 0), but the receipt isn't. It also isn't in any of the other chunks, or in any of the other blocks. Why is this?
Curl request that demonstrates the issue:
curl --location --request POST 'https://archival-rpc.mainnet.near.org' \
--header 'Content-Type: application/json' \
--data-raw '{
"method": "chunk",
"params": {
"block_id": 65694172,
"shard_id": 0
},
"jsonrpc": "2.0",
"id": 0
}'

Elasticsearch 6 create new field requires data type but "Indices created in 6.x only allow a single-type per index"

Create a new field in Elasticsearch 6.6.2 gives the following error:
{
"error": {
"root_cause": [
{
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: mapping type is missing;"
}
],
"type": "action_request_validation_exception",
"reason": "Validation Failed: 1: mapping type is missing;"
},
"status": 400
}
The request:
curl --request PUT http://10.1.3.81:9200/netswitch_message/_mapping -H "Content-Type: application/json" -d \
'{
"properties": {
"amount": {"type": "integer"}
}
}'
gives error no matter what data type I use. The index already has types integer, text/keyword, text and date.
curl --request PUT http://10.1.3.81:9200/netswitch_message/_mapping -H "Content-Type: application/json" -d "{\"properties\": {\"amount\": {\"type\": \"integer\"}}}"
curl --request PUT http://10.1.3.81:9200/netswitch_message/_mapping -H "Content-Type: application/json" -d "{\"properties\": {\"amount\": {\"type\": \"text\"}}}"
curl --request PUT http://10.1.3.81:9200/netswitch_message/_mapping/data -H "Content-Type: application/json" -d "{\"properties\": {\"amount\": {}}}"
curl --request PUT http://10.1.3.81:9200/netswitch_message/_mapping -H "Content-Type: application/json" -d "{\"properties\": {\"amount\": {}}}
Expected to create a new field
Actually got syntax error:
{"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation Failed: 1: mapping type is missing;"}],"type":"action_request_validation_exception","reason":"Validation Failed: 1: mapping type is missing;"},"status":400}
You are right that 6.x restricts you to a single _type, but you do still need to supply the name of that type (in 7.x, it defaults to _doc).
Change your mapping to specify the _type, like the following which sets it to "my-type":
curl --request PUT http://10.1.3.81:9200/netswitch_message/_mapping/my-type -H "Content-Type: application/json" -d \
'{
"properties": {
"amount": {"type": "integer"}
}
}'
See: https://www.elastic.co/guide/en/elasticsearch/reference/6.6/indices-put-mapping.html#indices-put-mapping

Elasticsearch 7 unable to create index

I am trying to create index using following syntax
curl -H "Content-Type: application/json" -XPUT 127.0.0.1:9200/movies -d '
{
"mappings": {
"movie": {
"properties": {
"year": {"type":"date"}
}
}
}
}'
I guess "movie" cannot be child of the "mappings", can someone please help me transform this into Elasticsearch 7 compatible syntax.
I tried using "movie.year" : {"type":"date"} but then it fails on following insert statement
curl -H "Content-Type: application/json" -XPUT 127.0.0.1:9200/movies/movie/109487 -d '
{
"genre":["IMAX", "Sci-Fi"],
"title":"Intersteller",
"year":2014
}'
I copied from tutorial of Elasticsearch 6
"Rejecting mapping update to [movies] as the final mapping would have
more than 1 type: [_doc, movie]"
In ES 7, there are no more types. You need to do it like this.
First, create the index:
curl -H "Content-Type: application/json" -XPUT 127.0.0.1:9200/movies -d '
{
"mappings": {
"properties": {
"year": {"type":"date"}
}
}
}'
Then, index your document:
curl -H "Content-Type: application/json" -XPUT 127.0.0.1:9200/movies/_doc/109487 -d '
{
"genre":["IMAX", "Sci-Fi"],
"title":"Intersteller",
"year":2014
}'

Updating Elasticsearch 5.6 index type with new mapping

I'd like to add a new mapping to an index I already have, I'm trying with
curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X PUT http://localhost:9200/videos_development/_mapping/video -d '
"video":{
"properties":{
"id_lookup":"text"
}
}
'
but it's returning
{"error":{"root_cause":[{"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}],"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"},"status":500}%
and I really have no idea what it means...
Can anybody help?
Your JSON is malformed, you need opening and closing curly braces + you're also missing the type in the field definition:
curl -H 'Content-Type: application/json' -H 'Accept: application/json' -X PUT http://localhost:9200/videos_development/_mapping/video -d '{
"video":{
"properties":{
"id_lookup": {
"type": "text"
}
}
}
}'

Elasticsearch Delete Query By Date

I'm running the following query :
q='{
"filtered" : {
"query" : {
"match_all" : {}
},
"filter": {
"and": [
{
"range": {
"creation_time": {
"from": "2012-08-30",
"to": "2012-08-31",
"include_lower": true,
"include_upper": true
}
}
},
]
}
}
}'
My domain is an ec2 server
curl -XDELETE "http://#{mydomain}:9200/monitoring/mention_reports/_query?q=#{q}"
When I am hitting this query it gives me
curl: (3) [globbing] nested braces not supported at pos 118
Please help me thanks
If you’re trying to exec curl from the command line, it should be looking like:
q='YOUR_QUERY_CODE_GOES_HERE'
curl -v -H "Content-type: application/json" -H "Accept: application/json" \
-XDELETE -d $q http://localhost:9200/monitoring/mention_reports/_query
In case of inside-ruby execution, you should format the request as you do, but the silver bullet is still in headers:
-H "Content-type: application/json" -H "Accept: application/json"

Resources