parse-community / parse-server

Parse Server for Node.js / Express
https://parseplatform.org
Apache License 2.0
20.9k stars 4.78k forks source link

Query for $text results in invalid key #4398

Closed nubu closed 6 years ago

nubu commented 6 years ago

Hey guys,

trying to query for $text values in my parse-installation not working. Always results in "invalid key" errors...

Parse-Server is version 2.7

dplewis commented 6 years ago

Can you provide the logs when running with VERBOSE=1 for this query please?

$text can only run on string fields

nubu commented 6 years ago

Of course: (thanks for the effort)

The field is "string" and set as an index.

Tried query: where={"$text" : {"$search" : {"message" : "was"}}} or where={"$text" : {"$search" : "was"}}

both same result.

full error-log: verbose: REQUEST for [GET] /parse/classes/Squad?where={%22$text%22%20:%20{%22$search%22%20:%20{%22message%22%20:%20%22was%22}}}: {} method=GET, url=/parse/classes/Squad?where={%22$text%22%20:%20{%22$search%22%20:%20{%22message%22%20:%20%22was%22}}}, host=localhost:1337, origin=http://0.0.0.0:4040, accept-encoding=gzip, deflate, connection=keep-alive, x-parse-master-key=96b783df-7978-42b2-ae95-daed347e7364, accept=*/*, user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0.1 Safari/604.3.5, x-parse-application-id=**, referer=http://0.0.0.0:4040/apps/**/api_console, accept-language=de-de, error: Error generating response. ParseError { code: 105, message: 'Invalid key name: $text' } code=105, message=Invalid key name: $text error: Invalid key name: $text code=105, message=Invalid key name: $text

dplewis commented 6 years ago

Your query isn't in the correct format.

http://docs.parseplatform.org/rest/guide/#queries-on-string-values

where={"field_name":{"$text":{"$search":{"$term":"was"}}}}

nubu commented 6 years ago

Seems to be the solution - even if I get an error, cause it's just a "normal" index and not a text index. Thought I can do so with mongo compass for example ...

dplewis commented 6 years ago

Using Parse-Server the text indexes are created for you so you shouldn’t see an error.

nubu commented 6 years ago

Ok, but what for we need the $term key? Looks like there isn't something like that in mongo itself. (Cause i want to search for "ell" and find entrys with "hello" - of course.

dplewis commented 6 years ago

Parse-Server has adapters that takes input and transform them into the database (Mongo / PG). Most of the time you won't be about to copy a query from parse-server and expect it to work in mongo / pg. For example there's no $text in Postgres. $term is needed because $search has other options and makes transform easier.

nubu commented 6 years ago

Ah okay - but how to do querys that doesn't match the string 100% - or just not possible with the current implementation?

best Nico

dplewis commented 6 years ago

You can use query.contains() or query.matches()

*They may run slow with large datasets

nubu commented 6 years ago

Hmm that's my approach at the moment - thought with "real text search" I can use a better alternative. - Is there another, performant, way ?

dplewis commented 6 years ago

You can always give ElasticSearch a try. Its a good alternative.