How can I specify a search field for Elastic Search - FATAL -- : [...] ArgumentError (Must specify fields to search): - searchkick

My rails 5 app is deployed to Heroku, but the search function results in a 500 status and tells me that I need to specify a search field for Elastic Search. Any help would be greatly appreciated.
repo: https://github.com/GBressler/moldy-eggplants
Heroku log:
2018-12-03T20:58:37.320538+00:00 app[web.1]: I, [2018-12-03T20:58:37.320469 #4] INFO -- : [cb92c5ee-9b97-4939-944e-14a06610a61b] Parameters: {"utf8"=>"✓", "search"=>"deadpool"}
2018-12-03T20:58:37.388702+00:00 app[web.1]: I, [2018-12-03T20:58:37.388584 #4] INFO -- : [cb92c5ee-9b97-4939-944e-14a06610a61b] Completed 500 Internal Server Error in 68ms (ActiveRecord: 0.0ms)
2018-12-03T20:58:37.399605+00:00 app[web.1]: F, [2018-12-03T20:58:37.399462 #4] FATAL -- : [cb92c5ee-9b97-4939-944e-14a06610a61b]
2018-12-03T20:58:37.399680+00:00 app[web.1]: F, [2018-12-03T20:58:37.399609 #4] FATAL -- : [cb92c5ee-9b97-4939-944e-14a06610a61b] ArgumentError (Must specify fields to search):
2018-12-03T20:58:37.399746+00:00 app[web.1]: F, [2018-12-03T20:58:37.399683 #4] FATAL -- : [cb92c5ee-9b97-4939-944e-14a06610a61b]
2018-12-03T20:58:37.399827+00:00 app[web.1]: F, [2018-12-03T20:58:37.399766 #4] FATAL -- : [cb92c5ee-9b97-4939-944e-14a06610a61b] app/controllers/movies_controller.rb:8:in `search'
2018-12-03T20:58:37.398344+00:00 heroku[router]: at=info method=GET path= "/movies/search?utf8= %E2%9C%93&search=deadpool" host=nameless-ravine-32235.herokuapp.com request_id=cb92c5ee-9b97-4939-944e-14a06610a61b fwd="179.6.192.118" dyno=web.1 connect=0ms service=86ms status=500 bytes=1827 protocol=https

It looks like your search parameter attribute is not whitelisted in your Movies controller.
# Never trust parameters from the scary internet, only allow the white list through.
def movie_params
params.require(:movie).permit(:title, :description, :movie_length, :director, :image, :rating)
end
In theory you can do something like ...
# Never trust parameters from the scary internet, only allow the white list through.
def movie_params
params.require(:movie).permit(:title, :description, :movie_length, :director, :image, :rating, :search)
end
Now when sending the params , just make sure it's wrapped in a movie object Parameters: {"utf8"=>"✓", "movie" => {"search"=>"deadpool"}}
Now just reference it accordingly in line 8 of your controller, so instead of params[:search], you'll now use movie_params[:search]. Did not test it, let me know if it works out.

Related

Issue with geo index in mongoAtlas

I´ve migrating my last mLab application with heroku to the new MongoAtlas platform. I found some issues when trying to create geo indexes for my collections.
Here is how I used to integrate the index in the mLab tool:
db.OpenDataMadrid.createIndex( {“location.coordinates” : “2dsphere” } )
db.OpenDataMadrid.createIndex( {“location.coordinates” : “2d” } )
db.BuscadoresDatasets.createIndex( {“location.coordinates” : “2dsphere” } )
db.BuscadoresDatasets.createIndex( {“location.coordinates” : “2d” } )
And now my new geo indexes for both collections are like this:
{
“mappings”: {
“dynamic”: true,
“fields”: {
“location”: {
“fields”: {
“coordinates”: [
{
“dynamic”: true,
“type”: “document”
},
{
“indexShapes”: true,
“type”: “geo”
}
]
},
“type”: “document”
}
}
}
}
But when I run the application and the $geoquery is done I receive the following error:
Exception: Query failed with error code 291 and error message 'error processing query: ns=gastrorecomendador.OpenDataMadrid limit=1Tree: GEONEAR field=location.coordinates maxdist=2 isNearSphere=0
2021-10-10T07:29:36.472781+00:00 app[web.1]: Sort: {}
2021-10-10T07:29:36.472781+00:00 app[web.1]: Proj: {}
2021-10-10T07:29:36.472787+00:00 app[web.1]: planner returned error :: caused by :: unable to find index for $geoNear query’ on server cluster0-shard-00-02.5ojd2.mongodb.net:27017
2021-10-10T07:29:36.585612+00:00 app[web.1]: Exception: Query failed with error code 291 and error message 'error processing query: ns=gastrorecomendador.OpenDataMadrid limit=300Tree: $and
2021-10-10T07:29:36.585620+00:00 app[web.1]: Type $eq “restaurant”
2021-10-10T07:29:36.585620+00:00 app[web.1]: Puntuacion $gt 3.5
2021-10-10T07:29:36.585621+00:00 app[web.1]: GEONEAR field=location.coordinates maxdist=250 isNearSphere=0
2021-10-10T07:29:36.585622+00:00 app[web.1]: Sort: {}
2021-10-10T07:29:36.585622+00:00 app[web.1]: Proj: {}
2021-10-10T07:29:36.585628+00:00 app[web.1]: planner returned error :: caused by :: unable to find index for $geoNear query’ on server cluster0-shard-00-02.5ojd2.mongodb.net:27017
Any help creating 2d and 2dphere indexes?
I’ve also try to create the index to the location variable instead of location.coordinates but it doesn’t work either.
Thanks in advance!

Time out error when using browser.getCurrentUrl() after URL changes

I am writing a protractor test for login for an AngularJS app and want to verify that the login is successful and the url changes after login. I tried to use Expected condition with urlContains() and also tried with browser.getCurrentUrl().toContain() but I am getting error in both.
exports.config = {
seleniumAddress : 'http://localhost:4444/wd/hub',
specs: ['login.spec.js'],
};
Expected condition passes the test when the url is correct. But when the url is different then it throws timeout error
"Failed: Wait timed out after 5013ms".
expect(browser.getCurrentUrl()).toContain('/dashboard') fails always with below error
Stack:
ScriptTimeoutError: script timeout: result was not received in 11 seconds
(Session info: chrome=75.0.3770.142)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.3', java.version: '12.0.1'
Driver info: driver.version: unknown
at Object.checkLegacyResponse (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/error.js:546:15)
at parseHttpResponse (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:509:13)
at doSend.then.response (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/http.js:441:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: Protractor.waitForAngular()
at thenableWebDriverProxy.schedule (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver.js:807:17)
at ProtractorBrowser.executeAsyncScript_ (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/built/browser.js:425:28)
at angularAppRoot.then (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/built/browser.js:456:33)
at ManagedPromise.invokeCallback_ (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1376:14)
at TaskQueue.execute_ (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:3084:14)
at TaskQueue.executeNext_ (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:3067:27)
at asyncRun (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2927:27)
at /Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:668:7
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: Run it("should login successfully") in control flow
at UserContext.<anonymous> (/Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/jasminewd2/index.js:94:19)
From asynchronous test:
Error
at Object.<anonymous> (/Users/ProtractorTest/Tests/login.spec.js:17:3)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at /Users/.nvm/versions/node/v8.9.4/lib/node_modules/protractor/node_modules/jasmine/lib/jasmine.js:93:5
Below is my code
it('should login successfully', function () {
browser.get("https://example.com/");
loginobj.username.sendKeys(logindata.email);
loginobj.password.sendKeys(logindata.password);
loginobj.loginbtn.click().then(function(){
browser.getCurrentUrl().then(url => expect(url).toContain('/dashboard'));
//var EC = protractor.ExpectedConditions;
//browser.wait(EC.urlContains('/dashboard'), 5000);
})
I expect that when the url is different than the expected one, it should display a valid error message instead of timeout error.
By default protractor handles all the asynchrony for you. Looking at your code you are relying on default protractor behaviour i.e. not setting SELENIUM_PROMISE_MANAGER to false.
In that case, why do you want to do something inside click().then() ? It can be as simple and plain as
loginobj.loginbtn.click();
expect(browser.getCurrentUrl()).toContain('/dashboard');
One theory with your code: once you have something inside click().then(), its out of place from the promise queue that protractor is handling for you. Unless it is absolutely necessary, for ex get value from an element for later use in the spec, I would suggest not to meddle with protractor asynchronous handling as much as possible.
Hope that helps.
I have something similar
const currentUrl = await browser.getCurrentUrl().then(url => url);
expect(currentUrl).toContain('/dashboard')
Try it out maybe it will help, just without await as i see you don't use async functions
or like this
await browser.getCurrentUrl().then(url => expect(url).toContain('/dashboard'));
In protractor default script time out is 11 seconds,
In above code snippet,
browser.getCurrentUrl().then(url => expect(url).toContain('/dashboard'));
statement takes more than 11 seconds to resolve promise.
Solution: In Protractor configuration file, add below statements
allScriptsTimeout: timeout_in_millis.
e.g for 30 second timeout
allScriptsTimeout: 30000
Edited Configuration File:
exports.config = {
allScriptsTimeout: 30000,
seleniumAddress : 'http://localhost:4444/wd/hub',
specs: ['login.spec.js'],
};

Google Cloud Functions GitHub auto-deployer says: The request has errors

I have installed the GitHub auto-deployer for Google Cloud Functions, but when I now push my function into my GitHub repository, I receive an abstract error message "The request has errors" with the following rather non-descript details. What could specifically be going wrong here?
E githubAutoDeployer [CODE] 2017-12-30 19:19:37.362
Failed to create function projects/[MY_BUCKET]/locations/us-central/functions/[MY_FUNCTION] { Error: The request has errors
at Request._callback (/user_code/node_modules/googleapis/node_modules/google-auth-library/lib/transporters.js:85:15)
at Request.self.callback (/user_code/node_modules/googleapis/node_modules/request/request.js:186:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/user_code/node_modules/googleapis/node_modules/request/request.js:1163:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous> (/user_code/node_modules/googleapis/node_modules/request/request.js:1085:12)
at IncomingMessage.g (events.js:292:16)
at emitNone (events.js:91:20)
code: 400,
errors:
[ { message: 'The request has errors',
domain: 'global',
reason: 'badRequest' } ] }
E githubAutoDeployer [CODE] 2017-12-30 19:19:37.363 Error: The request has errors
at Request._callback (/user_code/node_modules/googleapis/node_modules/google-auth-library/lib/transporters.js:85:15)
at Request.self.callback (/user_code/node_modules/googleapis/node_modules/request/request.js:186:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/user_code/node_modules/googleapis/node_modules/request/request.js:1163:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous> (/user_code/node_modules/googleapis/node_modules/request/request.js:1085:12)
at IncomingMessage.g (events.js:292:16)
at emitNone (events.js:91:20)
D githubAutoDeployer [CODE] 2017-12-30 19:19:37.365
Function execution took 2319 ms, finished with status code: 500
UPDATE The mentioning of google-auth-library in the stack trace made me think that something may be wrong with my credentials. But the output from gcloud auth list appears alright:
Credentialed Accounts
ACTIVE ACCOUNT
* [MY_ID]#gmail.com
UPDATE What is perhaps slightly unconventional is that I have "path":"", in my config.json. But then my index.js resides directly at the top of my repository, so there is no path to specify.
UPDATE This is where the error from Google Cloud Functions is passed on by githubAutoDeployer (unfortunately source code for the upstream server is apparently not available):
gcf.projects.locations.functions.create({ resource, location }, (err, operation) => {
if (err && err.errors && err.errors[0] && err.errors[0].reason === 'alreadyExists') {
// ...
} else if (err) {
console.error(`Failed to create function ${resource.name}`, err);
reject(err);
}
The trouble was that I was specifying "location" : "us-central" instead of us-central1 (which supports Google Cloud Functions) in my config.json.
I found out by sending a raw POST request to the Google Cloud Functions API (after obtaining a service account and access token, etc.). At this level the API returns a clear error indication:
"fieldViolations": [
{
"field": "region",
"description": "region us-central is not supported."
}
]
Apparently and unfortunately this does not enter any of the log files when githubAutoDeployer attempts the same call.

QuotaExceededError with pouchdb

I have a big error with pouchDB communicating to my Cloudant database in a angular/ionic app.
Can you please help me figure out how to fix this ?
POST https://louisromain.cloudant.com/boardline_users/_bulk_get?revs=true&attachments=true&_nonce=1446478625328 400 (Bad Request)
pouchdb.min.js:8 Database has a global failure DOMError {}message: ""name: "QuotaExceededError"__proto__: DOMErrora.8.G.onsuccess.H.onabort # pouchdb.min.js:8
ionic.bundle.min.js:139 o {status: 500, name: "abort", message: "unknown", error: true, reason: "QuotaExceededError"}error: truemessage: "unknown"name: "abort"reason: "QuotaExceededError"result: Objectdoc_write_failures: 1docs_read: 1docs_written: 0end_time: Mon Nov 02 2015 16:37:05 GMT+0100 (CET)errors: Array[1]last_seq: "3478-g1AAAAFJeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtXLSs1LLUst0kvOyS9NScwr0ctLLckBKmRKZEiy____f1YGUxIDA3N6LlCMPdXM1MzEMo1oM5IcgGRSPcKYcLAxKZYGlslpSajGmOA2Jo8FSDI0ACmgSftRXJSSamFoYWmOapQ5IaMOQIwCuooZZFQhxHPmJkCURtigLAAxFGUZ"ok: falsestart_time: Mon Nov 02 2015 16:36:59 GMT+0100 (CET)status: "aborting"__proto__: Objectstatus: 500__proto__: r(anonymous function) # ionic.bundle.min.js:139b.$get # ionic.bundle.min.js:111(anonymous function) # ionic.bundle.min.js:151a.$get.n.$eval # ionic.bundle.min.js:165a.$get.n.$digest # ionic.bundle.min.js:163(anonymous function) # ionic.bundle.min.js:166e # ionic.bundle.min.js:74(anonymous function) # ionic.bundle.min.js:76
11ionic.bundle.min.js:139 Error: Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.
at Error (native)
at a.9.n.openTransactionSafely (http://localhost:8101/lib/pouchdb/dist/pouchdb.min.js:8:9233)
at i.a.8.e._getLocal (http://localhost:8101/lib/pouchdb/dist/pouchdb.min.js:8:2521)
at i.<anonymous> (http://localhost:8101/lib/pouchdb/dist/pouchdb.min.js:7:6737)
at i.<anonymous> (http://localhost:8101/lib/pouchdb/dist/pouchdb.min.js:10:28092)
at i.a.90.t.exports (http://localhost:8101/lib/pouchdb/dist/pouchdb.min.js:10:28931)
at http://localhost:8101/lib/pouchdb/dist/pouchdb.min.js:9:28802
at i.<anonymous> (http://localhost:8101/lib/pouchdb/dist/pouchdb.min.js:9:28722)
at i.a.90.t.exports [as get] (http://localhost:8101/lib/pouchdb/dist/pouchdb.min.js:10:28931)
at i.angular.module.constant.service.$q.qify [as get] (http://localhost:8101/lib/angular-pouchdb/angular-pouchdb.js:35:27)(anonymous function) # ionic.bundle.min.js:139b.$get # ionic.bundle.min.js:111(anonymous function) # ionic.bundle.min.js:151a.$get.n.$eval # ionic.bundle.min.js:165a.$get.n.$digest # ionic.bundle.min.js:163(anonymous function) # ionic.bundle.min.js:166e # ionic.bundle.min.js:74(anonymous function) # ionic.bundle.min.js:76
The error is that the device has run out of space. Unfortunately this is an error thrown by IndexedDB itself when the device is too low on storage, so there's nothing you can do about it except to use less space. PouchDB's compact() can help; there's also the transform-pouch plugin if you want to just reduce the size of your documents.

Mongodb authentication using elixir-mongo

I have just started using Elixir, so I figure I have some basic misunderstanding going on here. Here is the code...
defmodule Mdb do
def connect(collection, this_db \\ "db-test") do
{:ok, mongo} = Mongo.connect("db-test.some-mongo-server.com", 12345)
db = mongo |> Mongo.db(this_db)
db |> Mongo.auth("user", "secretpassword")
db
end
end
I start with iex -S mix
and when I try db = Mdb.connect("users") I get
** (UndefinedFunctionError) undefined function: Mongo.auth/3
Mongo.auth(%Mongo.Db{auth: nil, mongo: %Mongo.Server{host: 'db-test.some-mongo-server.com', id_prefix: 12641, mode: :passive, opts: %{}, port: 12345, socket: #Port<0.5732>, timeout: 6000}, name: "db-stage", opts: %{mode: :passive, timeout: 6000}}, "user", "secretpassword")
(mdb_play) lib/mdb.ex:7: Mdb.connect/2
I looks like Mongo.auth/3 is undefined, but that makes no sense to me. Can any one point me towards my error?
thanks for the help
I just played around it, and faced the same error. As in the error message, Mongo.auth seems not defined, and it might be Mongo.Db.auth instead. However, I faced another error (ArgumentError) on Mongo.Db.auth too. It may be certain issue in the library.
** (ArgumentError) argument error
:erlang.byte_size
...
(mongo) lib/mongo_request.ex:43: Mongo.Request.cmd/3
(mongo) lib/mongo_db.ex:44: Mongo.Db.auth/1
I'm not familiar with the library, but after small change in Mongo.Db.auth, normal call seems started working.
I tried with the following sequence.
mongo = Mongo.connect!(server, port)
db = mongo |> Mongo.db(db_name)
db |> Mongo.Db.auth(user_name, password)
collection = db |> Mongo.Db.collection(collection_name)
collection |> Mongo.Collection.count()
The change I tried is in the following fork-repo.
https://github.com/parroty/elixir-mongo