How to implement AWS cloud search in Node js?

  • Cubettech
  • NodeJs
  • 8 years ago

How to Implement AWS Cloud Search in Nodejs
Cloud Search service provided by Amazon or AWS is well known for its guarantee in scalability and reliability. CloudSearch domain created in AWS management console for uploading data will catalyze the process of search implementation to your website without any hurdles. AWS cloud search provides user friendly atmosphere to fine tune your search criteria. Amazon CloudSearch scales our needs according to hits and volume.

Integrating with Node Js.

The preferred way to install the AWS SDK for Node.js is to use the npm package manager for Node.js.

npm install aws-sdk

Require the aws-sdk module

Pass the the credential information to the configuration object using

AWS.config.update({accessKeyId: ‘YOUR_KEY’, secretAccessKey: ‘YOUR_SECRET’});

Setting the Region

AWS.config.update({region: 'YOUR_REGION'}); // say us-west-1

Locking the API Version

You can use specific api version.

AWS.config.apiVersions = {  cloudsearchdomain: '2013-01-01',  // other service API versions };

Sending a Request Using CloudSearchDomain

var csd = new AWS.CloudSearchDomain({endpoint: ‘YOUR_SEARCH_DOMAIN’'}); var params = {  query: 'STRING_VALUE', /* required */  cursor: 'STRING_VALUE',  expr: 'STRING_VALUE',  facet: 'STRING_VALUE',  filterQuery: 'STRING_VALUE',  highlight: 'STRING_VALUE',  partial: true || false,  queryOptions: 'STRING_VALUE',  queryParser: 'simple | structured | lucene | dismax',  return: 'STRING_VALUE',  size: 0,  sort: 'STRING_VALUE',  start: 0 }; csd.search(params, function (err, data) {   if (err){ console.log(err, err.stack); // an error occurred   }else{console.log(data);           // successful response }});

Parameters used for Request

  • query: Specifies the search criteria for the request
  • cursor: Retrieves a cursor value you can use to page through large result sets.
  • expr: Defines one or more numeric expressions that can be used to sort results or specify search or filter criteria. Also expressions as return fields can be used.
  • facet: Specifies one or more fields for which to get facet information, and options that control how the facet information is returned.
  • filterQuery: Specifies a structured query that filters the results of a search without affecting how the results are scored and sorted. You use filterQuery in conjunction with the query parameter to filter the documents that match the constraints specified in the query parameter.
  • highlight: Retrieves highlights for matches in the specified text or text-array fields.
  • partial: Toggle partial results to be returned if one or more index partitions are unavailable.
  • queryOptions: Configures options for the query parser specified in the queryParser parameter.
  • queryParser: query parser to use to process the request, If queryParser is not specified, default one, simple query parser is used.
  • return: Specifies the field and expression values to include in the response.
  • size: Specifies the maximum number of search hits to include in the response.
  • sort: Specifies the fields or custom expressions to use to sort the search results.
  • start: Specifies the offset of the first search hit you want to return.

Hope this post will direct you through the right path when it comes to implementing AWS cloud search in Node js. If you have any concerns regarding the process, please don’t hesitate to drop a comment below.

Know More About This Topic from our Techies

Table of Contents

    Contact Us

    Contact

    What's on your mind? Tell us what you're looking for and we'll connect you to the right people.

    Let's discuss your project.

    Phone