Update cell Google Sheet API - google-sheets-api

Trying to update a cell in a Google Sheet with the source attached, I find the error "Invalid value at 'requests[0].update_cells' (oneof), oneof field 'area' is already set. Cannot set 'start'", and I don't know what I am doing wrong
[{
"updateCells"={
"fields"="totalUpdatedCells",
"range"={
"endColumnIndex"=179,
"endRowIndex"=7,
"sheetId"=XXXXX,
"startColumnIndex"=179,
"startRowIndex"=7
},
"rows"=[
{
"values"=[
{
"userEnteredValue"={
"stringValue"="My text"
}
}
]
}
],
"start"={
"columnIndex"=179,
"rowIndex"=7,
"sheetId"=XXXXX
}
}
}]
This is the concrete error:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid value at 'requests[0].update_cells' (oneof), oneof field 'area' is already set. Cannot set 'start'",
"reason" : "badRequest"
} ],
"message" : "Invalid value at 'requests[0].update_cells' (oneof), oneof field 'area' is already set. Cannot set 'start'",
"status" : "INVALID_ARGUMENT"
}
A hint from where can I throw?
EDIT for #Tanaike:
The body of request:
{
"requests"= [
{
"updateCells"= {
"fields"="userEnteredValue",
"rows"= [
{
"values"= [
{
"userEnteredValue"= {
"stringValue"="My text"
}
}
]
}
],
"start"= {
"columnIndex"=179,
"rowIndex"=7,
"sheetId"=XXXXX
}
}
}
]
}
and the error of request:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid requests[0].updateCells: GridCoordinate.columnIndex[179] is after last column in grid[25]",
"reason" : "badRequest"
} ],
"message" : "Invalid requests[0].updateCells: GridCoordinate.columnIndex[179] is after last column in grid[25]",
"status" : "INVALID_ARGUMENT"
}

I put the body of the request in case another user encounters the same problem:
{
requests=[
{
updateCells={
fields=userEnteredValue,
rows=[
{
values=[
{
userEnteredValue={
stringValue=My text
}
}
]
}
],
start={
columnIndex=6,
rowIndex=178,
sheetId=XXXXX
}
}
}
]
}
Thanks to #Tanaike for helping me find the answer

Related

Querying data from Elasticsearch

Using Elasticsearch 7.*, trying to execute SQL query on an index 'com-prod':
GET /com-prod/_search
{
"script_fields": {
"test1": {
"script": {
"lang": "painless",
"source": "params._source.ElapsedTime"
}
}
}
}
It gives the output and below as one of the hit successfully:
"hits" : [
{
"_index" : "com-prod",
"_type" : "_doc",
"_id" : "abcd",
"_score" : 1.0,
"fields" : {
"test1" : [
"29958"
]
}
}
Now, I am trying to increment the ElapsedTime by 2, as below:
GET /com-prod/_search
{
"script_fields": {
"test2": {
"script": {
"lang": "painless",
"source": "params._source.ElapsedTime + 2"
}
}
}
}
But its actually adding number 2 to the output, as below:
"hits" : [
{
"_index" : "com-prod",
"_type" : "_doc",
"_id" : "abcd",
"_score" : 1.0,
"fields" : {
"test2" : [
"299582"
]
}
}
Please guide what could be wrong here, and how to get the output as 29960.
You are getting 299582, instead of 29960, because the ElapsedTime field is of string type ("29958"), so when you are adding 2 in this using script, 2 gets appended at the end (similar to concat two strings).
So, in order to solve this issue, you can :
Create a new index, with updated mapping of the ElaspsedTIme field of int type, then reindex the data. Then you can use the same search query as given in the question above.
Convert the string to an int type value, using Integer.parseInt()
GET /com-prod/_search
{
"script_fields": {
"test2": {
"script": {
"lang": "painless",
"source": "Integer.parseInt(params._source.ElapsedTime) + 2"
}
}
}
}

Mapping ElasticSearch apache module field

I am new to ES and I am facing a little problem I am struggling with.
I integrated metricbeat apache module with ES and the it works fine.
The problem is that metricbeat apache module reports the KB of web traffic of apache (field apache.status.total_kbytes), instead I would like to create my own field, the name of which would be "apache.status.total_mbytes).
I am trying to create a new mapping via Dev Console using the followind api commands:
PUT /metricbeat-7.2.0/_mapping
{
"settings":{
},
"mappings" : {
"apache.status.total_mbytes" : {
"full_name" : "apache.status.total_mbytes",
"mapping" : {
"total_mbytes" : {
"type" : "long"
}
}
}
}
}
Still ES returns the following error:
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "Root mapping definition has unsupported parameters: [settings : {}] [mappings : {apache.status.total_mbytes={mapping={total_mbytes={type=long}}, full_name=apache.status.total_mbytes}}]"
}
],
"type" : "mapper_parsing_exception",
"reason" : "Root mapping definition has unsupported parameters: [settings : {}] [mappings : {apache.status.total_mbytes={mapping={total_mbytes={type=long}}, full_name=apache.status.total_mbytes}}]"
},
"status" : 400
}
FYI
The following may shed some light
GET /metricbeat-*/_mapping/field/apache.status.total_kbytes
Returns
{
"metricbeat-7.9.2-2020.10.06-000001" : {
"mappings" : {
"apache.status.total_kbytes" : {
"full_name" : "apache.status.total_kbytes",
"mapping" : {
"total_kbytes" : {
"type" : "long"
}
}
}
}
},
"metricbeat-7.2.0-2020.10.05-000001" : {
"mappings" : {
"apache.status.total_kbytes" : {
"full_name" : "apache.status.total_kbytes",
"mapping" : {
"total_kbytes" : {
"type" : "long"
}
}
}
}
}
}
What am I missing? Is the _mapping command wrong?
Thanks in advance,
A working example:
Create new index
PUT /metricbeat-7.2.0
{
"settings": {},
"mappings": {
"properties": {
"apache.status.total_kbytes": {
"type": "long"
}
}
}
}
Then GET metricbeat-7.2.0/_mapping/field/apache.status.total_kbytes will result in (same as your example):
{
"metricbeat-7.2.0" : {
"mappings" : {
"apache.status.total_kbytes" : {
"full_name" : "apache.status.total_kbytes",
"mapping" : {
"total_kbytes" : {
"type" : "long"
}
}
}
}
}
}
Now if you want to add a new field to an existing mapping use the API this way:
Update an existing index
PUT /metricbeat-7.2.0/_mapping
{
"properties": {
"total_mbytes": {
"type": "long"
}
}
}
Then GET metricbeat-7.2.0/_mapping will show you the updated mapping:
{
"metricbeat-7.2.0" : {
"mappings" : {
"properties" : {
"apache" : {
"properties" : {
"status" : {
"properties" : {
"total_kbytes" : {
"type" : "long"
}
}
}
}
},
"total_mbytes" : {
"type" : "long"
}
}
}
}
}
Also, take a look at Put Mapping Api

mapper_parsing_exception in Elasticsearch(Reason: No type specified for field [X])

I wanted to provide explicit mapping to the fields in my document, So I defined a mapping for my index demo and It looks like this below:
PUT /demo
{
"mappings": {
"properties": {
"X" : {
"X" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"Sub_X" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
After running the query , I am getting error as :
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "No type specified for field [X]"
}
],
"type" : "mapper_parsing_exception",
"reason" : "Failed to parse mapping [_doc]: No type specified for field [X]",
"caused_by" : {
"type" : "mapper_parsing_exception",
"reason" : "No type specified for field [X]"
}
},
"status" : 400
}
The field X in json document looks like :
"X" : {
"X" : [
"a"
],
"Sub_X" : [
[
"b"
]
]
},
Please help me out with this elastic search mapper_parse_exception error.
What you have is called nested data type
You have X which in turn contains X and Sub_X.
Mapping:
{
"properties": {
"X": {
"type": "nested"
}
}
}
Data:
{
"X": {
"X": [
"a"
],
"Sub_X": [
[
"b"
]
]
}
}
Query:
{
"query": {
"nested": {
"path": "X",
"query": {
"bool": {
"must": [
{ "match": { "X.X": "a" }},
{ "match": { "X.Sub_X": "b" }}
]
}
}
}
}
}
It outputs the document.

Rest Assured Exception - invalid JSON Schema, cannot continue

I am using TestNG along with Rest Assured.
We have json schema file. Inside the Json schema it refers to other schema using $ref attribute.
When I use matchesJsonSchemaInClasspath for Hamcrest assertion it is failing with an validation error.
The error is basically the Validator is unable to read the nested JSON schema.
Can someone help me to resolve the issue.
Error and the Json schemas are attached.
Error:
com.github.fge.jsonschema.core.exceptions.InvalidSchemaException:
fatal: invalid JSON Schema, cannot continue
Syntax errors:
[ {
"level" : "warning",
"schema" : {
"loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/response.json#",
"pointer" : ""
},
"domain" : "syntax",
"message" : "the following keywords are unknown and will be ignored: [javaType, name]",
"ignored" : [ "javaType", "name" ]
}, {
"level" : "error",
"message" : "value has incorrect type (found boolean, expected one of [array])",
"domain" : "syntax",
"schema" : {
"loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/service_header.json#",
"pointer" : ""
},
"keyword" : "required",
"found" : "boolean",
"expected" : [ "array" ]
}, {
"level" : "error",
"message" : "URI \"./service_header.json\" is not normalized",
"domain" : "syntax",
"schema" : {
"loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/service_header.json#",
"pointer" : "/properties/service_header"
},
"keyword" : "$ref",
"value" : "./service_header.json"
}, {
"level" : "error",
"message" : "value has incorrect type (found boolean, expected one of [array])",
"domain" : "syntax",
"schema" : {
"loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/service_header.json#",
"pointer" : "/properties/service_header"
},
"keyword" : "required",
"found" : "boolean",
"expected" : [ "array" ]
}, {
"level" : "error",
"message" : "value has incorrect type (found boolean, expected one of [array])",
"domain" : "syntax",
"schema" : {
"loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/service_item.json#",
"pointer" : "/properties/items"
},
"keyword" : "required",
"found" : "boolean",
"expected" : [ "array" ]
}, {
"level" : "error",
"message" : "URI \"./setvice_item.json\" is not normalized",
"domain" : "syntax",
"schema" : {
"loadingURI" : "file:/C:/GitWorkspace/OM/service_OM/functionalTest/target/test-classes/specs/specification/v1/schema/response/service_item.json#",
"pointer" : "/properties/items/items"
},
"keyword" : "$ref",
"value" : "./service_item.json"
} ]
level: "fatal"
JSON Schema:
main.json
{
"type":"object",
"$schema":"http://json-schema.org/draft-04/hyper-schema",
"name": "Response",
"title": "Response",
"javaType": "com.ruthresh.Response",
"description": "Enables you to make a POST response.",
"required":true,
"properties":{
"service_header":{
"type":"object",
"description": "The service header for a response.",
"required":true,
"$ref":"./service_header.json"
},
"items":{
"type":"array",
"description": "An array of individual items.",
"required":true,
"maxLength":5000,
"minLength":1,
"items":{
"$ref":"./service_item.json"
}
}
}
}
service_header.json
{
"type":"object",
"$schema":"http://json-schema.org/draft-04/hyper-schema",
"name":"service_header",
"title":"Service response Header",
"description":"The service header for a response.",
"id":"service_header:v1",
"javaType": "com.ruthresh.Header",
"required":true,
"properties":{
"email_subject":{
"type":"string",
"description":"Email subject.",
"maxLength":255
},
"email_message":{
"type":"string",
"description":"Email Message.",
"maxLength":4000
}
}
}
serivice_item.json
{
"type":"object",
"$schema":"http://json-schema.org/draft-04/hyper-schema",
"name":"serivice_item",
"title":"Service response Header",
"description":"The service header for a response.",
"id":"serivice_item:v1",
"javaType": "com.ruthresh.Item",
"required":true,
"properties":{
"item_subject":{
"type":"string",
"description":"Item subject.",
"maxLength":255
},
"item_message":{
"type":"string",
"description":"Item Message.",
"maxLength":4000
}
}
}
As the error message says, "required" should be an array of required properties and not boolean.

Elastic search Not filter inside and filter

I am trying to add a "not" filter inside "and" filter
Sample input:
{
"query":{
"filtered":{
"query":{
"query_string":{
"query":"error",
"fields":[
"request"
]
}
},
"filter":{
and:[
{
"terms":{
"hashtag":[
"br2"
]
},
"not":{
"terms":{
"hashtag":[
"br1"
]
}
}
}
]
}
}
}
},
}
But above is giving error, i also tried various combination but in vain.
Above is just an example in short i require a query in which both "and", "not" filter are present.
you forgot the "filters" array.
Write it like this :
{
"from" : 0,
"size" : 25,
"query" : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"and" : {
"filters" : [{
"term" : {
"field1" : "val1"
}
}, {
"not" : {
"filter" : {
"term" : {
"field2" : "val2",
}
}
}
}
]
}
}
}
}
}