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.
I am using ElasticSearch 7.7 in CentOS 8 box. I could creat index, type by REST format by command curl. For example, I could use
curl -X PUT "localhost:9200/testindex2"
curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/testindex2/man/1/" -d '{ "name" : "shiny2", "age": 28}'
curl -XGET "localhost:9200/testindex2/man/1/"
curl -XGET "localhost:9200/testindex2/man/_search?pretty"
But if I have inserted many documents, how could I do query by REST command line using command curl to find particular age = 28's documents?
curl -XGET "localhost:9200/testindex2/_search?pretty&q=age:28"
that is the simplest way to query.
more option and documentation:
https://www.elastic.co/guide/en/elasticsearch/reference/7.8/search-search.html
also you can use Match or Term query with JSON body format.
curl -XGET 'localhost:9200/testindex2/_search?pretty' -d '
{
"query": {
"term": {
"age": {
"value": "28"
}
}
}
}'
more documentation:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
ELK 7.X
I am trying to create elastic search watcher with curl using the input file. Something like this
curl -X PUT _watcher/watch/cluster_health_watch --data-binary #inputFile
1) What is the file type to be used ? Most of the data is json, but in "actions" field when sending an email, the email body can be HTML !
2) Is there any way that the HTML in the body can be referred from an external file, such that input file can be json ?
Just escaped the double quotes in the html string by adding "\".
Ex:-
<h3 style=\"color:red\"></h3>
"actions": {
"send_email": {
"email": {
"to": "xxxx#gmail.com",
"subject": "My Subject",
"body": {
"html": "<h3 style=\"color:red\"> There was a problem</h3>"
}
}
}
}
curl -X PUT _watcher/watch/cluster_health_watch -H 'Content-Type: application/json' --data-binary #inputFile.json
How to update couchbase lite view with Rest API ?
From Rest API how to tell indexer that view is updated . I have tried the below code but it did not work.It still returns the old index.
What is the correct way of telling indexer that view is updated so that it can recreate the index.
'PUT'
{db}/_design/todo
{
"_rev":"hf675757577hhfh",
"views":{
"list":{
"map":function(doc){
if(doc.type=='list')
{
emit(doc._id,{"name":doc.name});
}
},
//"version":"1.0" (I have tryied this but not work)
}
}
}
//My view create request was like below:
{db}/_design/todo
{
"views":{
"list":{
"map":function(doc){
if(doc.type=='list')
{
emit(doc._id,{"name":doc.name});
}
},
//"version":"1.0" (I have tryied this but not work)
}
}
}
It looks like you may just have some formatting problems. This shows how to do what you're trying from the command line:
curl -X PUT 'http://localhost:4985/db/_design/todo' --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "_rev": "hf675757577hhfh", "views": { "list": { "map": "function(doc) { if (doc.type == \"list\") { emit(doc._id, { \"name\": doc.name }); }}"}}}'
You can test your results with this command:
curl -X GET 'http://localhost:4985/db/_design/todo/_view/list'
You may want to refer to the documentation, which has more examples, at https://developer.couchbase.com/documentation/mobile/current/guides/sync-gateway/views/index.html
I insert data to Elasticsearch with id 123
localhost:9200/index/type/123
but I do not know what will next id inserted
how insert data to Elasticsearch without id in localhost:9200/index/type?
The index operation can be executed without specifying the id. In such a case, an id will be generated automatically. In addition, the op_type will automatically be set to create. Here is an example (note the POST used instead of PUT):
$ curl -XPOST 'http://localhost:9200/twitter/tweet/' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elasticsearch"
}'
In my case, using nodejs and the elasticsearch package I did it this way using the client:
client.index ()
var elasticsearch = require ('elasticsearch');
let client = new elasticsearch.Client ({
host: '127.0.0.1: 9200'
});
client.index ({
index: 'myindex'
type: 'mytype',
body: {
properti1: 'val 1',
properti2: ['y', 'z'],
properti3: true,
}
}, function (error, response) {
if (error) {
console.log("error: ", error);
} else {
console.log("response: ", response);
}
});
if an id is not specified, elasticsearch will generate one automatically
In my case, I was trying to add a document directly to an index, e.g. localhost:9200/messages, as opposed to localhost:9200/someIndex/messages.
I had to append /_doc to the URL for my POST to succeed: localhost:9200/messages/_doc. Otherwise, I was getting an HTTP 405:
{"error":"Incorrect HTTP method for uri [/messages] and method [POST], allowed: [GET, PUT, HEAD, DELETE]","status":405}
Here's my full cURL request:
$ curl -X POST "localhost:9200/messages/_doc" -H 'Content-Type:
application/json' -d'
{
"user": "Jimmy Doe",
"text": "Actually, my only brother!",
"timestamp": "something"
}
'
{"_index":"messages","_type":"_doc","_id":"AIRF8GYBjAnm5hquWm61","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":2,"_primary_term":3}
You can use POST request to create a new document or data object without specifying id property in the path.
curl -XPOST 'http://localhost:9200/stackoverflow/question' -d '
{
title: "How to insert data to elasticsearch without id in the path?"
}
If our data doesn’t have a natural ID, we can let Elasticsearch autogenerate one for us. The structure of the request changes: instead of using the PUT verb ("store this document at this URL"), we use the POST verb ("store this document under this URL").
The URL now contains just the _index and the _type:
curl -X POST "localhost:9200/website/blog/" -H 'Content-Type: application/json' -d'
{
"title": "My second blog entry",
"text": "Still trying this out...",
"date": "2014/01/01"
}
'
The response is similar to what we saw before, except that the _id field has been generated for us:
{
"_index": "website",
"_type": "blog",
"_id": "AVFgSgVHUP18jI2wRx0w",
"_version": 1,
"created": true
}
Autogenerated IDs are 20 character long, URL-safe, Base64-encoded GUID strings. These GUIDs are generated from a modified FlakeID scheme which allows multiple nodes to be generating unique IDs in parallel with essentially zero chance of collision.
https://www.elastic.co/guide/en/elasticsearch/guide/current/index-doc.html
It's possible to leave the ID field blank and elasticsearch will assign it one. For example a _bulk insert will look like
{"create":{"_index":"products","_type":"product"}}\n
{JSON document 1}\n
{"create":{"_index":"products","_type":"product"}}\n
{JSON document 2}\n
{"create":{"_index":"products","_type":"product"}}\n
{JSON document 3}\n
...and so on
The IDs will look something like 'AUvGyJMOOA8IPUB04vbF'