Repository navigation
Closed
Description
I've been troubleshooting some gcloud-ruby issues connecting to the Cloud Search API. I've been looking at gcloud-node's implementation, and I can't get find a way to specify multiple returnFields values.
Here is my setup:
$ nodejs
> var gcloud = require('gcloud')(...);
undefined
> var search = gcloud.search();
undefined
> var index = search.index('test');
undefined
> var printSearchResults = function(err, documents) {
... if (err) {
..... console.log('there was an error');
..... console.log(err);
..... } else {
..... console.log('the search results were returned:');
..... console.log(documents);
..... }
... }
undefined
I can perform a simple search without specifying any returnFields values:
> index.search('ruby', printSearchResults);
undefined
> the search results were returned:
[ { metadata: {},
baseUrl: '/documents',
parent:
{ metadata: {},
baseUrl: '/indexes',
parent: [Object],
id: 'test',
createMethod: undefined,
create: undefined,
delete: undefined,
exists: undefined,
get: undefined,
getMetadata: undefined,
setMetadata: undefined },
id: 'gcloud-ruby',
createMethod: undefined,
setMetadata: undefined,
fields: {} } ]
undefined
And I can specify a single returnFields value:
> index.search({query: 'ruby', returnFields: '*'}, printSearchResults);
undefined
> the search results were returned:
[ { metadata: {},
baseUrl: '/documents',
parent:
{ metadata: {},
baseUrl: '/indexes',
parent: [Object],
id: 'test',
createMethod: undefined,
create: undefined,
delete: undefined,
exists: undefined,
get: undefined,
getMetadata: undefined,
setMetadata: undefined },
id: 'gcloud-ruby',
createMethod: undefined,
setMetadata: undefined,
fields: { summary: [Object], title: [Object], description: [Object] } } ]
undefined
The trouble I run into is specifying multiple values:
> index.search({query: 'ruby', returnFields: ['title', 'summary', 'description']}, printSearchResults);
undefined
> there was an error
{ errors: undefined,
code: 400,
message: 'Invalid JSON payload received. Unknown name "returnFields[1]": Cannot bind query parameter. Field \'returnFields[1]\' could not be found in request message.\nInvalid JSON payload received. Unknown name "returnFields[2]": Cannot bind query parameter. Field \'returnFields[2]\' could not be found in request message.\nInvalid JSON payload received. Unknown name "returnFields[0]": Cannot bind query parameter. Field \'returnFields[0]\' could not be found in request message.',
response: undefined }
undefined
>
Metadata
Metadata
Assignees
Labels
No labels
Activity
stephenplusplus commentedon Dec 2, 2015
Thanks for the report! I'll get on this 👍
callmehiphop commentedon Dec 3, 2015
I looked into this a little bit,
requestuses a module calledqsinternally, this is a code sample from their docsThis explains the problem we're seeing and it looks like we can get around it by passing
requestaqsStringifyOptionsobject withindicesset tofalse. Do we know if that's the standard way the upstream API deals with query strings? Just curious about if it would be safe to turn of indices globally or if we'll need to handle this on a case by case basis.stephenplusplus commentedon Dec 7, 2015
That's interesting. From the request docs, we can also use
useQuerystring: trueto use the default querystring module which loses the indices.But in this case, it looks like the API wants a string and not a list of strings:
returnFieldsSearchResultobjects. It can be fields fromDocument, the built-in fields_rankand_score, and fields defined infieldExpressions. Use"*"to return all fields fromDocument.Looks like there is either a discrepancy in the type or an unknown delimter... subscribed to googleapis/google-cloud-ruby#450 so we can see what needs to be done here when that's resolved.
chore(deps): update dependency sinon to v13 (#986)
chore(main): release 5.2.0 (#986)
chore(main): release 5.2.0 (#986)
fix(build): migrate to using main branch (#986)
fix: add close() in the wrapper (#986)
chore(main): release 3.9.0 (#985)
fix: add close() in the wrapper (#986)
chore(main): release 3.9.0 (#985)
fix: add close() in the wrapper (#986)
chore(main): release 3.9.0 (#985)
fix: add close() in the wrapper (googleapis#986)
chore(main): release 3.9.0 (googleapis#985)