Skip to content
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

Searching with presence/absense fails due to JSON encoding strings as lists #3

Closed
mjcollin opened this issue May 18, 2015 · 2 comments

Comments

@mjcollin
Copy link
Contributor

df = idig_search_records(rq=list("scientificname"=list("type"="missing")))

This search is encoded as ?rq={"scientificname":{"type":["missing"]}} which has the "missing" as a list. See this jsonlite ticket:

jeroen/jsonlite#73

Fails with an error when trying to decode the response from the server: this is an API-side bug. The API should be returning JSON error messages even when the query results in a 500 error because Elasticsearch can't run the query.

Ref: iDigBio/idigbio-search-api#2

@mjcollin
Copy link
Contributor Author

Doing the JSON conversion outside of httr::POST with jsonlite::toJSON(, auto_unbox=FALSE) works but also results in single element arguments to parameters that expect a list eg fields. fields_exclude, and top_fields, to be a string instead of a list which the API fails on. Catch-22.

Alex is looking at changing the API behaviour to allow for both strings and single item lists as arguments because Elasticsearch already behaves this way in a number of places to it won't feel inconsistent.

(Ref another solution on the R side, maintain a list of everything that has to be list and fixup the object prior to JSON encoding with appropriate calls to I() : jeroen/jsonlite#78 )

@mjcollin
Copy link
Contributor Author

Alex has adjusted the API to allow for mixed single item list and strings for API parameters. Now have unboxing on so things that get passed through to Elasticsearch meet ES's expectations.

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

1 participant