Showing posts with label Search. Show all posts
Showing posts with label Search. Show all posts

Tuesday, June 16, 2015

Apache Solr to Amazon CloudSearch migration tool


In this post, we are introducing a new tool called S2C – Apache Solr to Amazon CloudSearch Migration Tool. S2C is a Linux console based utility that helps developers / engineers to migrate search index from Apache Solr to Amazon CloudSearch.
Very often customers initially build search for their website or application on top of Solr, but later run into challenges like elastic scaling and managing the Solr servers. This is a typical scenario we have observed in our years of search implementation experience. For such use cases, Amazon CloudSearch is a good choice. Amazon CloudSearch is a fully-managed service in the cloud that makes it easy to set up, manage, and scale a search solution for your website. To know more, please read the Amazon CloudSearch documentation
We are seeing growing trend every year, organizations of various sizes are migrating their workloads to Amazon CloudSearch and leveraging the benefits of fully managed service. For example, Measured Search, an analytics and e-Commerce platform vendor, found it easier to migrate to Amazon CloudSearch rather than scale Solr themselves (see article for details).
Since Amazon CloudSearch is built on top of Solr, it exposes all the key features of Solr while providing the benefits of a fully managed service in the cloud such as auto-scaling, self-healing clusters, high availability, data durability, security and monitoring.
In this post, we provide step-by-step instructions on how to use the Apache Solr to Amazon CloudSearch Migration (S2C) tool to migrate from Apache Solr to Amazon CloudSearch.
Before we get into detail, you can download the S2C tool in the below link.
Download Link: https://s3-us-west-2.amazonaws.com/s2c-tool/s2c-cli.zip

Pre-Requisites

Before starting the migration, the following pre-requisites have to be met. The pre-requisites include installations and configuration on the migration server. The migration server could be the same Solr server or independent server that sits between your Solr server and Amazon CloudSearch instance.  
Note: We recommend running the migration from the Solr server instead of independent server as it can save time and bandwidth. It is much better if the Solr server is hosted on EC2 as the latency between EC2 and CloudSearch is relatively less.
The following installations and configuration should be done on the migration server (i.e. your Solr server or any new independent server that connects between your Solr machine and Amazon CloudSearch).
  
1.      The application is developed using Java. Download and Install Java 8 .Validate the JDK path and ensure the environment variables like JAVA_HOME, classpath, path is set correctly.

2.      We assume you already have setup Amazon Web services IAM account. Please ensure the IAM user has right permissions to access AWS services like CloudSearch.
Note: If you do not have an AWS IAM account with above mentioned permissions, you cannot proceed further.

3.      The IAM user should have AWS Access key and Secret key. In the application hosting server, set up the Amazon environment variables for access key and secret key. It is important that the application runs using the AWS environment variables.
To setup AWS environment variables, please read the below link.

Alternatively, you can set the following AWS environment variables by running the commands below from Linux console.

export AWS_ACCESS_KEY=Access Key  
export AWS_SECRET_KEY=Secret Key

4.      Note: This step is applicable only if the application is hosted on Amazon EC2.
If you do not have an AWS Access key and Secret key, you can opt for IAM role attached to an EC2 instance. A new IAM role can be created and attached to EC2 during the instance launch. The IAM role should have access to AWS resources like S3, DynamoDB and CloudSearch.
For more information, read the below link

5.      Download the migration utility ‘S2C’, unzip the tool and copy it in your working directory.

S2C Utility File
The downloaded ‘S2C’ migration utility should have the following sub directories and files.
Folder / Files
Description




bin
Binaries of the migration tool




lib
Libraries required for migration




application.conf
Configuration file that allows end users to input parameters
Require end-user’s input.



logback.xml
Log file configuration
Optional. Does not require end-user  / developer input



s2c
script file that executes the migration process


Configure only application.conf and logback.xml.  Do not modify any other file.                                                                                                                                         
application.conf
The application.conf file has the configuration related to the new Amazon CloudSearch domain that will be created. The parameters configured in the in the application.conf file are explained in the table below.
s2c {
  api {
    SchemaParser = "s2c.impl.solr.DefaultSchemaParser"
    SchemaConverter = "s2c.impl.cs.DefaultSchemaConverter"
    DataFetcher = "s2c.impl.solr.DefaultDataFetcher"
    DataPusher = "s2c.impl.cs.DefaultDataPusher"  }
List of API that is executed step by step during the migration.

Do not change this.


  solr {
    dir = "files"
    server-url = "http://localhost:8983/solr/collection1"
    fetch-limit = 100
  }
dir – The base directory path of Solr.

Ensure the directory is present and also its validity.

Eg:/opt/solr/example/solr/collection1/conf

server-url – Server host, port and collection path

The endpoint which will be used to fetch the data.
If the utility is run from a different server, ensure the IP address and port has firewall access.
fetch-limit – number of solr documents that can be fetched for each batch call

This configuration number should be carefully set by the developer.

The fetch limit depends on the following factors:
1.  Record size of a Solr record(1KB or 2KB)
2.  Latency between migration server and Amazon CloudSearch
3.  Current Request Load on the Solr Server


E.g.: If the total Solr documents is 100000 and fetch limit is 100, then it would take 100000 / 10 = 10000 batch calls to complete the fetch.

If size of each Solr record is 2KB, then 100000 * 2KB = 200MB data is migrated.



  cs {
    domain = "collection1"
    region = "us-east-1"
    instance-type = " search.m3.xlarge"
    partition-count = 1
    replication-count = 1
  }
domain - CloudSearch domain name
Ensure that the domain name does not already exist.
Region – AWS region for the new CloudSearch domain
Instance type – Desired instance type for CloudSearch nodes

Choose the instance type based on the volume of data and the expected query volume.


Partition count – Number of partitions required for CloudSearch 
replication-count - Replication count for CloudSearch


wd = "/tmp"
Temporary file path to store intermediate data files and migration log files

Running the migration

Before launching the S2C migration tool, verify the following:
1.      Solr directory path – Make sure that the Solr directory path is valid and available. The tool cannot read the configuration if the path or directory is invalid.
2.      Solr configuration contents - Validate that the Solr configuration contents are correctly set inside the directory. Example: solrconfig.xml, schema.xml, stopwords.txt, etc.
3.      Make sure that the working directory is present in the file system and has write permissions for the current user. It can be an existing directory or a new directory. The working directory stores the fetched data from Solr and migration logs.
4.      Validate the disk size before starting the migration. If the available free disk space is lesser than the size of the Solr index, the fetch operations will fail.
For example, if the Solr index size is 7 GB, make sure that the disk has at least 10 GB to 20 GB of free space.
Note: The tool reads the data from Solr and stores in a temporary directory (Please see configuration wd = /tmp in the above table).
5.      Verify that the AWS environment variables are set correctly. The AWS environment variables are mentioned in the pre-requisites section above.
6.      Validate the firewall rules for IP address and ports if the migration tool is run from a different server or instance. Example: Solr default port 8983 should be opened to the EC2 instance executing this tool.
Run the following command from directory ‘{S2C filepath}’ example: /build/install/s2c-cli
./s2c
Or
JVM_OPTS="-Xms2048m -Xmx2048m" ./s2c (With heap size)

The above will invoke the shell ‘s2c’ script that starts the search migration process. The migration process is a series of steps that require user inputs as shown in the screen shots below.
Step 1: Parse the Solr schema
The first step of migration prompts for a confirmation to parse the Solr schema and Solr configuration file. During this step, the application generates a ‘Run Id’ folder inside the working directory.
Example: /tmp/s2c/m1416220194655



The Run Id is a unique identifier for each migration. Note down the Run Id as you will need it to resume the migration in case of any failure.


Step 2: Schema conversion from Solr to CloudSearch
The second step prompts confirmation to convert Solr schema to CloudSearch schema. Press any key to proceed further.



The second step will also list all the converted fields which are ready to be migrated from Solr to CloudSearch. If any fields are left out, this step will allow you to correct the original schema. User can abort the migration and identify the ignored fields, rectify the schema and re-run the migration again.
The below screen shot shows the fields ready for CloudSearch migration.


Step 3: Data Fetch
The third step prompts for confirmation to fetch the search index data from the Solr server. Press any key to proceed. This step will generate a temporary file which will be stored in the working directory. This temporary file will have all the fetched documents from the Solr index.


There is also option to skip the fetch process if all the Solr data is already stored in the temporary file. If this is the case, the prompt will look like the screenshot below.



Step 4: Data push to CloudSearch
The last and final step prompts for confirmation to push the search data from the temporary file store to Amazon CloudSearch. This step also creates the CloudSearch domain with the configuration specified in application.conf including desired instance type, replication count, and multi-AZ options.


If the domain is already created, the utility will prompt to use the existing domain. If you do not wish to use an existing domain, you can create a new CloudSearch domain using the same prompt.
Note: The console does not prompt for any ‘CloudSearch domain name’ but instead it uses the domain name configured in the application.conf file.


Step 5: Resume (Optional)
During the migration steps, if there is any failure during the fetch operation, it can be resumed. This is illustrated in the screen shot below. 


Step 6: Verification
Log into AWS CloudSearch management console to verify that the domain and index fields.



Amazon CloudSearch allows running test queries to validate the migration and as well the functionality of your application.

Features supported
1.      Support for other non-Linux environments is not available for now.
2.      Support for Solr Shards is not available for now. The Solr shard needs to be migrated separately.
3.      The install commands may vary for different Linux flavors. Example installing software, file editor command, permission set commands can be different for every Linux flavors. It is left to engineering team to choose the right commands during the installation and execution of this migration tool.
4.      Only fields configured as ‘stored’ in Solr schema.xml are supported. The non-stored fields are ignored during schema parsing.
5.      The document id (unique key) is required to have following attributes:
a.      Document ID should be 128 characters or less in size.
b.      Document ID can contain any letter, any number, and any of the following characters:      _ - = # ; : / ? @ &
c.       The below link will help you to understand in data  preparation before migrating to CloudSearch http://docs.aws.amazon.com/cloudsearch/latest/developerguide/preparing-data.html
6.      If the conditions are not met in a document, it will be skipped during migration. Skipped records are shown in the log file.
7.      If a field type (mapped to fields) is not stored, the stopwords mapped to that particular field type are ignored.
Example 1:
<field name="description" type="text_general" indexed="true" stored="true" />   
The above field ‘description’ will be considered for stopwords.
Example 2:
<field name="fileName" type="string" />     
The above field ‘fileName’ will not be migrated and ignored in the stopwords.


Tuesday, April 23, 2013

Apache Solr 4 Cook Book Review

Book Review : Apache Solr 4 Cookbook Review
Author: Rafal Kuc
Reviewed by : Harish Ganesan and Vijay Olety
Book URL : http://www.packtpub.com/apache-solr-4-cookbook/book

Comments : 

I recently read this book and i am really impressed! This book provides good understanding of Apache Solr for both developers as well as consultants.
The book starts off well with an introduction to Apache Solr, the web / app servers required, the role of Zookeeper, why clustering your data is vital ?, the various directory implementations, performance-oriented caching mechanisms, a sample crawler module which coupled with Solr gives a complete end-to-end solution, the role of Apache Tika as a extracting toolkit and the ease of customizing Solr. From then on, the book dwells into the details.
The first step is indexing. It plays a vital part in the entire search solution. Data can be in the form on .txt, .pdf or any other format. It is imperative that all such formats are easily indexable. One of the widely used tools for extracting metadata and language detection is Apache Tika. Data can also be present in a database, for which the Data Import Handler is handy. It comes in two variants – full and delta. Every detail is nicely explained with examples which can make the development time faster. DIH also helps us to modify the data while importing which I felt is a pretty neat feature! One of the nicest features included in Solr 4 is the ability to update single field in a document. I am not sure why this was included in the earlier versions but it’s a classic case of better late than never.
The next step in the pipeline is the data analysis which is achieved through the use of analyzers and tokenizers. Various use cases include elimination HTML and XML tags, copying the contents of one field to another and stemming words amongst others. The detailing that has gone into explaining every concept, the examples and the associated step-by-step explanation is really helpful.
Now that the data is indexed and the data preparation is completed, it’s time to query Apache Solr! Searches can be performed on individual words or on a phrase. You can boost or elevate certain documents over others based on your requirements. Simple concepts such as sorting and faceting of results to complex ones such as ignoring typos using n-grams and detecting duplicates are very simple to understand and perform. Faceting, in particular, is gaining momentum as it helps in implementing the auto-suggest feature and narrowing down the search criteria. A newly introduced feature called the pivot faceting was a much needed one and it vastly simplifies certain use cases related to faceting. Solr provides immense capabilities when it comes to querying and this book explains each of them in great detail taking real-world examples.
We indexed and queried the data. But as our application scales, we have to get our hands dirty and start fine-tuning the performance metrics in order to give a good user experience to our customers. This is where caches and its various flavors and granularities starts to make sense. Cache always plays a major role in any deployment and it is necessary to monitor Solr at all times to gauge its performance. This book can done a great job in clearly explaining the various types of caches, the commit operation and its impact on searchers and how to overcome these. This topic is really important for any Solr real-world deployment and this book has not let me down!
Apache Solr 4.0 introduced the most-awaited SolrCloud feature that allows us to use distributed indexing and searching. Setting up of SolrCloud cluster along with a Zookeeper ensemble to enable replication, fault-tolerance and high availability along with disaster recovery is a piece-of-a-cake now. I really appreciate the time and effort spent on documenting and explaining how to set up two collections inside a single cluster. It was a nightmare to find information on this particular topic when we implementing SolrCloud for one of our customers. But I am rest assured that others referring this book will save precious time of theirs. Adding / deleting nodes from a cluster is no longer a tedious task as the entire process is automated through the presence of Zookeeper nodes. The in-depth knowledge of the author in these topics is clearly visible and is of great help to all the readers. A touch on Zookeeper Rolling Restart, though off-topic, might enable readers to get a complete birds-eye view of the entire cluster. Certain features such as soft commit and NRT search have been explained in detail afterwards (under Real-life Situations) but I felt that at least a mention earlier on would have provided a much needed continuity in that section. For the geeky readers like me, a detailed description about load balancing across shards and replicas and their customizations, if any, would have added an extra amount of spice to this well-cooked food!
As with any other tool, Solr deployment too will run into some kind of a problem. This section details the common problems that are encountered and effective ways to overcome these. Shrinking the size of the index and allocating enough memory in advance amongst others are some of the solutions explained in detail and is clearly documented in this book.
Lastly, as every developer would have wanted it, the real-world scenarios are described and the various Solr concepts that were explained in earlier sections are put together as part of a complete end-to-end solution.
Any one trying Solr 4.0 must read this book in its entirety before recommending a Solr production architecture. As mentioned above, there are a few suggestions which if incorporated in this book would benefit readers. All in all, this book will be really helpful for the developers and consultants alike!


Friday, March 15, 2013

Migration from Apache Solr to Amazon CloudSearch

Apache Solr is the popular, blazing fast open source enterprise search platform from the Apache Lucene project. It is one of the most widely used search platform in Amazon web services as wellby many product companies and SaaS platforms. Some of the major features include powerful full-text search, hit highlighting, faceted search, near real-time indexing, dynamic clustering, database integration, rich document  handling, and geospatial search etc. Apache Solr has recently launched Solr (v4.X) named SolrCloud,  which is highly reliable, scalable and fault tolerant, providing distributed indexing, replication and load-balanced querying, automated failover and recovery, centralized configuration and more. Apache Solr already powers the search and navigation features of many of the world’s largest internet sites and with this new launch they have signaled their competitors.



To know more about Apache SolrCloud deployment best practices on Amazon VPC, Refer article:  http://harish11g.blogspot.in/2013/03/Apache-Solr-cloud-on-Amazon-EC2-AWS-VPC-implementation-deployment.html


Amazon Web Services introduced a search service called Amazon CloudSearch sometime back. It is based on their robust A9 search platform. Amazon CloudSearch equally offers lots of features like Solr for searching. In addition CloudSearch is built in with automatic Scalability , Sharding and Availability. These infra features are tempting for many architects and product managers to port their applications from Solr to CloudSearch and reap the benefits.



To know more about how Apache Solr compares with Amazon CloudSearch, Refer article:  http://harish11g.blogspot.in/2013/01/amazon-cloudsearch-vs-apache-solr_16.html


In this article , let us explore the migration from Apache Solr to Amazon CloudSearch.

Know your show stoppers before migration :

Customers who are looking to develop a product which has cloud and on-premise editions should carefully evaluate their considerations before taking this migration approach. Amazon CloudSearch is a cloud dependent service and it cannot be moved on premise. If VPN or direct connect can be established between Customer DC and Amazon Web services, then some amount of viability is there for this approach. If the customer use case does not provide feasibility for this connectivity approach, then Apache Solr on Amazon EC2 will be a better approach on their product.

Customers who are looking at Cloud portability or Cloud Lock-in should carefully evaluate their approach before taking this migration. CloudSearch is a Amazon Web Service dependent service. (Note: When java was launched in late 90's customers were worried about same lock-in issues for architecting applications using this new technology. But a decade later, Java is the market leader. I feel the same vibe while working on AWS.)

Customers who want full control of their search environment (logs, security, disk encryption etc) should understand that CloudSearch is a web service and it does not provide those at this instant of time. For such deep security needs Apache Solr on Amazon VPC with TrendMicro/Safenet suite of products will suffice. Apache Solr on Amazon EC2 inside VPC with suite of security products available on the AWS marketplace will help you assemble a robust architecture on Amazon cloud.

Bottom line is that for your search module needs Amazon IaaS provides the best possible flexibility either thru cloudSearch or Apache Solr or AWS Marketplace products.



To know more about how to configure Apache Solr on Amazon VPC, Refer article:  http://harish11g.blogspot.in/2013/03/Configuring-installing-Apache-Solrcloud-solr4.x-on-Amazon-VPC-EC2-AWS.html



Compelling reasons why customers move to Amazon CloudSearch


"Amazon CloudSearch is a fully-managed service, When you migrate to Amazon CloudSearch, you no longer have to worry about provisioning and managing your own search fleet and scaling the fleet as your volume of data and traffic fluctuate. Amazon CloudSearch handles all of this for you behind the scenes. You don't need to make allowances for sharding in your application code; your index is automatically moved to a larger instance type or partitioned across multiple instances as needed for optimal performance." - from AWS documentation 

Economics behind the Migration

Some time back i did a cost comparison analysis between Amazon CloudSearch and Apache Solr(v3.6) on AWS. I found Amazon CloudSearch is cost effective in comparison to Apache Solr on the use cases detailed. 
Refer URL : http://harish11g.blogspot.in/2013/02/amazon-cloudsearch-solr-cost-comparison.html

As mentioned earlier in my other blog posts Solr 4.X has solved some of the infra problems and i feel it will still reduce the overall cost compared to Solr v3.6. I have not yet done the detailed comparison on this with CloudSearch, but i still feel Amazon CloudSearch will edge out Solr on costs. 



Migrating Your Application

Migrating your application from Solr to Amazon CloudSearch is a relatively straightforward process. You need to:

  • Create an Amazon CloudSearch domain. A search domain encapsulates your searchable data and the search instances that handle your search requests.
  • Map your Solr schema to Amazon CloudSearch index fields. Once you create your search domain, you define index fields to configure Amazon CloudSearch to handle your data the same way Solr did.
  • Implement your boosting and sorting preferences using rank expressions. Rank expressions are reusable Javascript-style expressions that you can define and use to customize how your results are ranked.
  • Submit Your Data Using the Amazon CloudSearch Search Data Format. You need to adapt your application to submit data to Amazon CloudSearch instead of Solr. Data can be submitted to Amazon CloudSearch in either JSON or XML.
  • Convert Your Solr queries to the Amazon CloudSearch search syntax. Once you've uploaded your data, you're ready to start submitting search requests to your domain's search endpoint using the Amazon CloudSearch search syntax.
  • Display the results from Amazon CloudSearch. The response format is very similar to Solr, but note that by default Amazon CloudSearch returns responses in JSON. To get responses in XML, you need to specify the response format in each search request.



Amazon Web Services has published an excellent article detailing the migration process. Refer URL for the same : http://aws.amazon.com/articles/8817853176055090




Other Related Articles:




Need Consulting help ?

Name

Email *

Message *

DISCLAIMER
All posts, comments, views expressed in this blog are my own and does not represent the positions or views of my past, present or future employers. The intention of this blog is to share my experience and views. Content is subject to change without any notice. While I would do my best to quote the original author or copyright owners wherever I reference them, if you find any of the content / images violating copyright, please let me know and I will act upon it immediately. Lastly, I encourage you to share the content of this blog in general with other online communities for non-commercial and educational purposes.

Followers