Reputation: 31
I have the following marklogic rest-api url :
http://marklogicserver:8060/v1/search?format=json&options=optionname&q=question
This url send me results and format them according the optionname. Everything is ok.
Now I need to do the same work with Nodejs API :
I use a querybuilder to do the same thing but my results are never formatted according to optionname.
qb.optionsName = 'optionname';
//qb.search = {q: question};
db.documents.query(
qb.where(qb.parsedFrom(‘question’))
).result( function(results) {
results.forEach(function(document) {
console.log(JSON.stringify(document,null,2));
return document;
});
}).catch(function (error){
console.log(error);
});
Although I am sure that the optioname is the right one, the system returns the following error message:
[Error: query documents: response with invalid 400 status]
message: 'query documents: response with invalid 400 status',
statusCode: 400,
body:
{ errorResponse:
{ statusCode: 400,
status: 'Bad Request',
messageCode: 'REST-INVALIDPARAM',
message: 'REST-INVALIDPARAM: (err:FOER0000) Invalid parameter: No configured options: optionname' } }
Upvotes: 3
Views: 183
Reputation: 31
Someone from marklogic gave me the good syntax:
my query.search was malformed, if it can help somebody.
var query = qb.where();
query.optionsName = 'optionsname';
query.categories = ['none'];
query.search = {
'options':{
'search-option':['unfiltered']
},
'qtext': 'q'
};
db.documents
.query(query)
.result( function(results) {
console.log(JSON.stringify(results,null,2));
})
.catch(function (error) {
console.log(error);
});
}
Thank you very much :)
Upvotes: 0
Reputation: 7335
The QueryBuilder defines the query entirely in the client. This approach gives the application complete flexibility for dynamic construction of queries and avoids the housekeeping of maintaining persisted query options.
To use query options persisted on the server, you can instead define a combined query as a JavaScript object and identify the persisted query options in that object:
http://docs.marklogic.com/jsdoc/documents.html#toc14
However, the QueryBuilder alternative is recommended.
Hoping that clarifies,
Upvotes: 2
Reputation: 7736
You are not passing the querybuilder to the function but a query built by it. Try creating the query and then attaching the optionsName property like this:
var query = qb.where(qb.parsedFrom(‘question’))
query.optionsName = 'optionname';
db.documents
.query(query)
.result( function(results) {
results.forEach(function(document) {
console.log(JSON.stringify(document,null,2));
return document;
});
})
.catch(function (error){
console.log(error);
});
Upvotes: 2