Skip to content

Query for $text results in invalid key #4398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nubu opened this issue Nov 28, 2017 · 11 comments
Closed

Query for $text results in invalid key #4398

nubu opened this issue Nov 28, 2017 · 11 comments

Comments

@nubu
Copy link

nubu commented Nov 28, 2017

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
Copy link
Member

dplewis commented Nov 28, 2017

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

$text can only run on string fields

@nubu
Copy link
Author

nubu commented Nov 28, 2017

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
Copy link
Member

dplewis commented Nov 28, 2017

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
Copy link
Author

nubu commented Nov 28, 2017

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
Copy link
Member

dplewis commented Nov 28, 2017

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

@nubu
Copy link
Author

nubu commented Nov 28, 2017

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
Copy link
Member

dplewis commented Nov 28, 2017

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.

@dplewis dplewis closed this as completed Nov 28, 2017
@nubu
Copy link
Author

nubu commented Nov 28, 2017

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
Copy link
Member

dplewis commented Nov 28, 2017

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

*They may run slow with large datasets

@nubu
Copy link
Author

nubu commented Nov 28, 2017

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
Copy link
Member

dplewis commented Dec 1, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants