Code Monkey home page Code Monkey logo

amazon-cloudsearch-client-java's Introduction

This project is no longer maintained. This project was created to fill the gap in the Amazon Aws Java Sdk. Amazon has added missing search features to their sdk. Please use the offical sdk https://github.com/aws/aws-sdk-java/tree/master/aws-java-sdk-cloudsearch

Amazon Cloudsearch Client Java

Amazon CloudSearch Client for Document Service and Searching. Amazon SDK does not provide java client for document indexing and seacrching. This simple library is created to fill that gap.

Instantiate Client

aws.services.cloudsearchv2.AmazonCloudSearchClient extends the official com.amazonaws.services.cloudsearchv2.AmazonCloudSearchClient client. So all the official funtionality is avaible with this client as well.

AWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);;
AmazonCloudSearchClient client = new AmazonCloudSearchClient(awsCredentials);
client.setSearchDomain(searchEndpoint);
client.setDocumentDomain(documentEndpoint);

Adding/Updating Documents

Adding single document:

AmazonCloudSearchAddRequest addRequest = new AmazonCloudSearchAddRequest();
addRequest.id = "acb123";
addRequest.version = 1;
addRequest.addField("text_field", "Some Value");
addRequest.addField("int_field", 123);

documentService.addDocument(addRequest);

More efficent to add multiple documents in a batch:

AmazonCloudSearchAddRequest addRequest1 = new AmazonCloudSearchAddRequest();
addRequest1.id = "acb123";
addRequest1.version = 1;
addRequest1.addField("text_field", "Some Value");
addRequest1.addField("int_field", 123);

AmazonCloudSearchAddRequest addRequest2 = new AmazonCloudSearchAddRequest();
addRequest2.id = "xyz123";
addRequest2.version = 1;
addRequest2.addField("text_field", "Some Value");
addRequest2.addField("int_field", 123);

List<AmazonCloudSearchAddRequest> addRequests = new ArrayList<>();

addRequests.add(addRequest1);
addRequests.add(addRequest2);

documentService.addDocument(addRequests);

Deleting Documents

AmazonCloudSearchAddRequest deleteRequest = new AwsCSDeleteRequest();
deleteRequest.id = "acb123";
deleteRequest.version = 1;

documentService.deleteDocument(deleteRequest);

Again more efficent to delete multiple documents in a batch:

AmazonCloudSearchDeleteRequest deleteRequest1 = new AmazonCloudSearchDeleteRequest();
deleteRequest1.id = "acb123";
deleteRequest1.version = 1;

AmazonCloudSearchDeleteRequest deleteRequest2 = new AmazonCloudSearchDeleteRequest();
deleteRequest2.id = "acb223";
deleteRequest2.version = 1;

List<AmazonCloudSearchDeleteRequest> deleteRequests = new ArrayList<>();

deleteRequests.add(deleteRequest1);
deleteRequests.add(deleteRequest1);

documentService.deleteDocument(deleteRequests);

Search Documents

For complete docuemntation of all the fields and options see:

http://docs.aws.amazon.com/cloudsearch/latest/developerguide/search-api.html

Below is a simple example of searching documents.

AmazonCloudSearchQuery query = new AmazonCloudSearchQuery();
query.query = "Dining Tables";
query.queryParser = "simple";
query.start = 0;
query.size = 16;
query.setDefaultOperator("or");
query.setFields("sku_no^11", "title^10", "description^9", "features^8", "specification^8", "categories^7");
query.addExpression("sort_expr", "(0.3*popularity)+(0.7*_score)");
query.addSort("sort_expr", "desc");

AmazonCloudSearchResult result = client.search(query);

Dependencies

  • Amazon SDK 1.9.33 and higher
  • Apache Fluent HC Module 4.2 and higher

Maven

<dependency>      
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-java-sdk-cloudsearch</artifactId>
  <version>1.9.33</version>
</dependency>    
<dependency>      
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>fluent-hc</artifactId>
  <version>4.2</version>
</dependency>

amazon-cloudsearch-client-java's People

Contributors

tahseen avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.