Google big query "required parameter missing" with ruby gem - ruby

I'm using Google's ruby api client to talk to big query and I have it all set up and working, except for queries where I'm getting this error:
{"error"=>
{"errors"=>
[{"reason"=>"required",
"domain"=>"global",
"message"=>"Required parameter is missing"}],
"code"=>400,
"message"=>"Required parameter is missing"}}
Here is what I'm calling:
bq = client.discovered_api("bigquery", "v2")
resp = client.execute(
bq.jobs.query,
{ "projectId" => "1234",
"query" => "SELECT count(*) FROM [api_logs.api_logs_week_28__Jul_2012] where timestamp >= 1341817200 and timestamp <= 1341903599"
}
)
The frustrating part is on the query api docs, these same exact parameters work just fine. Any ideas?

First- - I don't know ruby, but I do know bigquery, so I've taken a look at the ruby google drive example and tried to adapt it:
result = client.execute(
:api_method => bq.jobs.query,
:body_object => { "query" => "SELECT 17" },
:parameters => { "projectId => "1234" })
Essentially the projectId needs to be a parameter, and the query needs to be in the post data.

Related

Error on MongoId query with any_of and conditions on a same attribute

When running the following MongoId query
Project.any_of(
{ completed_at: nil}, { :completed_at.gte => #start_date}
)
it produces this error:
"This method is not prepared to handle key being a Key and serializer being not nil"
I found the validation code for this here but I don't understand what it means.
Using .where( "$or" => [ produces the same error.
MongoId v7.1.5, Rails v6.0, MongoDB 4.4.x
The generic string for this to be like this :
criteria.any_of({ :field1 => "value" }, { :field2 => "value2" })
This is an issue in Mongoid..

Change ElasticSearch track_total_hits in NEST

I was running thought examples of ElasticSearch, and read this link that says that there is a default set at 10,000, which also can be changed on the search calls, like on this example
GET twitter/_search
{
"track_total_hits": 100,
"query": {
"match" : {
"message" : "Elasticsearch"
}
}
}
The problem is, I'm trying to do the same on NEST, but I don't manage to replicate it. The only thing similar that I found, only accept a Boolean value and not a number. It is possible to change the total through NEST?
Here is the code that I tried:
var results = elasticClient.Search<MyClass>(s => s
.Query(q => q.QueryString(q2 => q2.Query(readLine)
.Fields(f => f.Field(p => p.MyField)))).TrackTotalHits(true));
As stated by #russcam here at the moment you can do it via casting ISearchRequest to IRequest<SearchRequestParameters>:
var client = new ElasticClient();
var searchResponse = client.Search<Document>(s =>
{
IRequest<SearchRequestParameters> request = s;
request.RequestParameters.SetQueryString("track_total_hits", 1000);
return s;
});
It will apply it as querystring parameter

Nest DeleteByQuery without the Object name

I want to send a Nest delete request to elasticsearch without specifying the object which I don't have. I've seen solutions like:
var response = elasticClient.DeleteByQuery<MyClass>(q => q
.Match(m => m.OnField(f => f.Guid).Equals(someObject.Guid))
);
From: DeleteByQuery using NEST and ElasticSearch
As I'm just reading plain text from a queue I don't have access to the MyClass object to use with the delete request. Basically I just want to delete all documents in an index (whose name I know) where a variable matches for example ordId = 1234. Something like:
var response = client.DeleteByQuery<string>( q => q
.Index(indexName)
.AllTypes()
.Routing(route)
.Query(rq => rq
.Term("orgId", "1234"))
);
I see that the nest IElasticClient interface does have a DeleteByQuery method that doesn't require the mapping object but just not sure how to implement it.
You can just specify object as the document type T for DeleteByQuery<T> - just be sure to explicitly provide the index name and type name to target in this case. T is used to provide strongly type access within the body of the request only. For example,
var client = new ElasticClient();
var deleteByQueryResponse = client.DeleteByQuery<object>(d => d
.Index("index-name")
.Type("type-name")
.Query(q => q
.Term("orgId", "1234")
)
);
Will generate the following query
POST http://localhost:9200/index-name/type-name/_delete_by_query
{
"query": {
"term": {
"orgId": {
"value": "1234"
}
}
}
}
Replace _delete_by_query with _search in the URI first, to ensure you're targeting the expected documents :)

How to search on multiple fields with boost weights?

At the moment I'm using this:
response = await ElasticClient.SearchAsync<Product>(s => s
.From(skip)
.Size(productSearch.ItemsPerPage)
.Index(productSearch.Company + PartOfIndexName + productSearch.Country)
.Query(q => q
.QueryString(c => c
.Fields(f => f
.Field(p => p.IdPart1, 4.0)
.Field(p => p.Title, 4.0)
.Field(p => p.BrandName, 3.0)
.Field(p => p.Description, 2.0)
)
.Query("*" + productSearch.Query + "*")
)
)
);
But this doesn't work. No results get returned. But I get a valid response (debug information: "Valid NEST response built from a successful low level call on POST"). Does anyone have any idea what I'm doing wrong? It's been days now and I still can't figure it out.
When I query it via the Elasticsearch REST API like this:
POST http://localhost:9200/company_products_country/_search
body:
{
"size": 10,
"query": {
"match": {
"title": "something"
}
}
}
Then it works and I get results. But if I search the description field for something like: "787920/1", then I get no results. The description field is a 500 char text field.
I index the documents like this:
ElasticClient.Index(product, idx => idx.Index(indexName));

Error constructing Gmail API request in Ruby

I'm having troubles sending a draft in Gmail through their API and the documentation doesn't help very much, especially since I'm working with Ruby.
I can create a draft without any issue, but then when I try to send the newly created draft, I get an error saying:
ArgumentError (wrong number of arguments (0 for 1))
The involved code is as follows:
#gmail = client.discovered_api('gmail', 'v1')
#send_result = client.execute(
:api_method => #gmail.users.drafts.send,
:parameters => { 'userId' => 'me' },
:body_object => { 'id' => '<message_id>' }
)
Taking a look at the debugger, the error seems to appear because of this:
#gmail.users.drafts.send
What am I missing here? I haven't seen anywhere that I should be passing parameters into the api_method? Also where can I find where this is documented and what is the parameter supposed to be?
Thanks!
The question is pretty old at this point, but I just ran into the same problem and figured it's better to answer late than never.
#gmail.users.drafts.send is colliding with Ruby's Object#send. You can work around the collision by converting the Google::APIClient::Resource item to a hash and then reading the value by key:
:api_method => #gmail.users.drafts.to_h["gmail.users.drafts.send"]
Your example, including the workaround:
#gmail = client.discovered_api('gmail', 'v1')
#send_result = client.execute(
:api_method => #gmail.users.drafts.to_h["gmail.users.drafts.send"],
:parameters => { 'userId' => 'me' },
:body_object => { 'id' => '<message_id>' }
)
I hope that helps!
I'm just going off of:
https://developers.google.com/gmail/api/v1/reference/users/drafts/send
But I think you have it right. The userId should be a parameter (e.g. in the URL) and the draft ID should be in the (POST) body. Can you confirm you're actually providing a draft ID and not the message.id?
Are you able to get an HTTP trace of the actual request, that would help immensely (you should likely be able to set this on the client or underlying http library your client uses, etc).

Resources