I am getting this error in elasticsearch - elasticsearch

{
"error":"Content-Type header [application/x-www-form-urlencoded] is not supported",
"status":406
}
Though I used header Content-Type
Here is the the command I used for indexing a customer document for a customer index:
curl -XPUT localhost:9200/customer/doc/1 -H 'Content-Type:application/json' -d '{"name":"abcd"}'

Related

Invalid Argument on API Call?

I am getting an invalid argument with the following API Call (following https://developers.google.com/nest/device-access/api/doorbell-battery#webrtc):
curl -X POST 'https://smartdevicemanagement.googleapis.com/v1/enterprises/projectID/devices/deviceID:executeCommand' -H 'Content-Type: application/json'
-H 'Authorization: AUTHTOKEN' --data-raw '{
"command" : "sdm.devices.commands.CameraLiveStream.GenerateWebRtcStream",
"params" : {
"offerSdp" : "a=recvonly"
}
}'
Response from server:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT"
}
}
What is the invalid argument?
My impression is that is not a valid offer, and you need to use a web rtc client to create it. See webrtc.org for examples.
"offerSdp" : "a=recvonly" isn't a valid offer, but also you will get that INVALID_ARGUMENT error if you don't end your offer string with a \r\n character.

Post JSON data to elastic search using curl command

I am trying to post Json file to elastic search and facing below errors
curl -XPOST http://localhost/test-index/doc -H "Content-Type: application/json" -d #test.json
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [test-index] as the final mapping would have more than 1 type: [_doc, doc]"}],"type":"illegal_argument_exception","reason":"Rejecting mapping update to [test-index] as the final mapping would have more than 1 type: [_doc, doc]"},"status":400}
test.json content
{
"name":"John Smith",
"age":"38"
}
am I missing anything
To post Json data to elasticsearch using curl command, you can try out this command:
curl -XPOST http://localhost:9200/test-index/_doc -H "Content-Type: application/json" -d #test.json
The command with which, you are trying to post Json file, works fine with Postman.
The error returned is
"reason":"Rejecting mapping update to [test-index] as the final
mapping would have more than 1 type: [_doc, doc]"}]
it mean that your index already have a type _doc and you try to create a new type doc. As version ~7.?? of elastic support only one type you can't create your data.
You need to add "_" before doc in your request.
http://localhost/test-index/doc <-- not correct
http://localhost/test-index/_doc <-- correct

Search query to match all and return all data without using curl

I am working with postman and i want to try using getting all data from my index, now when using curl
curl -X GET "localhost:9200/_search" -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}
but i want to write a search and return all data, my index name is tourdata and type is tours
127.0.0.1:9200/tourdata/tours/_search
how do i continue
So i found that i need to add size to my query parameter, This worked for me.
127.0.0.1:9200/tourdata/tours/_search?size=7000&pretty=true

Elastic Search is not working

When I am giving request to Elastic search my post and put is not working
My request
POST bird/admin/1
{
"id":"1",
"ity":"BSP"
}
It should give success
But, getting error
{
"error": "Content-Type header [application/x-www-form-urlencoded; charset=UTF-8] is not supported",
"status": 406
}
You should use application/json content type.
If you are using curl, add -H 'Content-Type: application/json'
https://www.elastic.co/blog/strict-content-type-checking-for-elasticsearch-rest-requests

How do I map the JSON body of a GET request to a parameter?

I have the following definition in my endpoint:
params do
requires :entities do
requires :id, type: String
optional :email, type: String
optional :phone, type: String
end
end
post "test" do
end
Note this only works as a POST request and the following CURL will work:
curl -XPOST localhost/test
-H 'Content-Type: application/json'
-H 'Accept: application/json'
-d '{ "entities": [{ "id": 3, "email": "test#abc.com" }] }'
However, the moment I change the declaration to get "test" instead of post, the corresponding curl request with -XGET no longer works due to the following validation error:
{"error":"entities is missing"}
If I remove the params requirements I can manually inspect the params hash at runtime and see that it only has a single key "route_info"
I'm currently using Grape 0.7.0
It happens because by specifying -d option you pass parameters in the body of the request while your endpoint is expecting them in the path as part of the url. Check here why it's a bad idea to pass body parameters in a GET request.
However, can use that option but if combination with -G.
-G, --get
When used, this option will make all data specified with -d, --data, --data-binary or --data-urlencode to be used in an HTTP GET request
instead of the POST request that otherwise would be used. The data will be appended to the URL with a '?' separator.
So that your get request by using -d would look like:
curl -XGET -G localhost/test
-H 'Content-Type: application/json'
-H 'Accept: application/json'
-d '{ "entities": [{ "id": 3, "email": "test#abc.com" }] }'

Resources