Cloud Search REST API

This document provides examples on typical query combinations you will use in an application to build unique search experiences. You can always experiment with queries from the query pad in the dashboard.

To perform a query, make an HTTPS request to the endpoint https://cs-api.nodechef.com/search and set the "X-Nodechef-Application-Id" header.
Cloud search supports the mongoDB extended JSON encoding in both strict and shell mode. This allows you to properly encode dates and binary types.


Curl Example

curl -X POST \ -H "X-Nodechef-Application-Id: ${APPLICATION_ID}" \ -H "Content-Type: application/json" \ -d '{"class": "books" , filter : {price : {$lt : 20 } }, textquery : {phrase : "that which became has be" \ fuzzy : 1, gap : 1, options : { \ queryfields : [{name : "title"}] \ } \ } \ }' \ https://cs.api.nodechef.com/search


Query format

{ class : "sample" filter : { age : { $lt : 20 }, height : { $gt : 1.87 } }, textquery : { AND : "Moon walk", fuzzy : 2, options : { queryfields : [{name : "", boost : "" }, { name : "" } ], queryhighlight : 1, querysuggestions : 1, queryboostexpr : { exp : "", field : "" } } }, limit : 10, skip : 5, sort : { _created_at : -1 }, project : { title : 1, name : 1 }, join : <Any valid query document> count : 1, }


Query format explained




textquery.options.queryboostexpr Examples

Cloud search supports boosting using C# expressions. We elected to use C# for the boosting expressions as it turned out to be significantly faster than javascript on all benchmarks. This is very crucial as the boosting expression must be applied to millions of matches in some cases. You do not have to be a c# expert to use this feature. More than often, boosting expressions are as simple as one line expressions using the built in c# the math library.

{ exp : "return current_score + Math.Log(1 + 0.1 * value.ToInt32())" field : "votes", } # Boost the relevance of an object in the query results by running an expression on the votes field in the object. # Generated C# function for the above expression: public static double ExprBoost(double current_score, DBValue value, DBValue param) { return current_score + Math.Log(1 + 0.1 * value.ToInt32()) }
Parameter Description
current_score The current score of the document computed using Nodechef cloud search practical scoring function which uses tf/idf and a coordination factor. This function is similar to lucene's practical scoring function
value Contains the value from the document referenced in the boost.field attribute in the search document. From the above example, value will contain the number_of_votes attribute from each document. Only indexed fields can be referenced. This is crucial for performance.
param Allows you to pass a parameter into the scoring function. This parameter can be of type int32, int64, double, datetime, string and array
cache When set to true, caches the compiled expression for reuse on subsequent queries

Methods of the DBValue struct

  • intToInt32()
  • longToInt64()
  • doubleToDouble()
  • floatToFloat()
  • decimalToDecimal()
  • datetimeToDateTime()
  • stringToString()
  • DBPointToDBPoint()
    DBPoint has the properties: GetX (x/latitude) and GetY (y/longitude).
  • List<DBValue>GetList()