Searchly

Page last updated:

Search made simple.

Managing Services

Managing services from the command line

Using Service Instances with your Application

See Delivering Service Credentials to an Application and VCAP_SERVICES Environment Variable.

Format of credentials in VCAP_SERVICES environment variable.

{
  searchly: [
    {
      name: "searchly-1",
      label: "searchly",
      tags: [ ],
      plan: "starter",
      credentials: {
        uri: "http://cloudfoundry:f0d15584ef7b5dcd1c5c1794ef3506ec@api.searchbox.io",
        sslUri: "https://cloudfoundry:f0d15584ef7b5dcd1c5c1794ef3506ec@api.searchbox.io"
      }
    }
  ]
}

Spring

Jest is a Java HTTP Rest client for ElasticSearch.It is actively developed and tested by Searchly.

Configuration

Ensure you have added Sonatype repository to your pom.xml

 <repositories>
 .
 .
   <repository>
     <id>sonatype</id>
     <name>Sonatype Groups</name>
     <url>https://oss.sonatype.org/content/groups/public/</url>
   </repository>
 .
 .
 </repositories>

With Maven add Jest dependency to your pom.xml

 <dependency>
   <groupId>io.searchbox</groupId>
   <artifactId>jest</artifactId>
   <version>0.0.5</version>
 </dependency>

Install Jest via Maven

$ mvn clean install

Configuration

Create a Jest Client Bean:

@Configuration
public class SpringConfiguration {

    @Bean
    public JestClient jestClient() throws Exception {

        // Using jackson to parse VCAP_SERVICES
        Map result = new ObjectMapper().readValue(System.getenv("VCAP_SERVICES"), HashMap.class);

        String connectionUrl = (String) ((Map) ((Map) ((List)
                    result.get("searchly")).get(0)).get("credentials")).get("uri");
        // Configuration
        ClientConfig clientConfig = new ClientConfig.Builder(connectionUrl).multiThreaded(true).build();

        // Construct a new Jest client according to configuration via factory
        JestClientFactory factory = new JestClientFactory();
        factory.setClientConfig(clientConfig);
        return factory.getObject();
    }
}

Indexing

Create an index via Jest with ease;

client.execute(new CreateIndex.Builder("articles").build());

Create new document.

Article source = new Article();
source.setAuthor("John Ronald Reuel Tolkien");
source.setContent("The Lord of the Rings is an epic high fantasy novel");

Index article to “articles” index with “article” type.

Index index = new Index.Builder(source).index("articles").type("article").build();
client.execute(index);

Searching

Search queries can be either JSON String or ElasticSearch SearchSourceBuilder object (You need to add ElasticSearch dependency for SearchSourceBuilder).

String query = "{\n" +
    "    \"query\": {\n" +
    "        \"filtered\" : {\n" +
    "            \"query\" : {\n" +
    "                \"query_string\" : {\n" +
    "                    \"query\" : \"Lord\"\n" +
    "                }\n" +
    "            }\n"+
    "        }\n" +
    "    }\n" +
    "}";

Search search = (Search) new Search.Builder(query)
// multiple index or types can be added.
.addIndexName("articles")
.addIndexType("article")
.build();

List<Article> result = client.getSourceAsObjectList(Article.class);

Jest has very detailed documentation at it’s github page.

Rails

Configuration

Ruby on Rails applications will need to add the following entry into their Gemfile.

gem 'tire'

Update application dependencies with bundler. shell $ bundle install Configure Tire in configure/application.rb or configure/environment/production.rb

# top of Application.configure
require 'json'
..
..
..

Tire.configure do
    url JSON.parse(ENV['VCAP_SERVICES']['searchly'][0]['credentials']['uri'])
end

Search

Make your model searchable:

class Document < ActiveRecord::Base
  include Tire::Model::Search
  include Tire::Model::Callbacks
end

When you now save a record:

Document.create :name => "Cost",
               :text => "Cost is claimed to be reduced and in a public cloud delivery model capital expenditure is converted."

The included callbacks automatically add the document to a documents index, making the record searchable:

@documents = Document.search 'Cost'

Tire has very detailed documentation at it’s github page.

Node.js

elasticsearchclient is a lightweight ElasticSearch client for Node.js. It is actively developed and covers core modules of ElasticSearch.

Configuration

Add elasticsearchclient dependency to your package.json file and use npm to install your dependencies

"dependencies": {
   "elasticsearchclient":">=0.5.1"
}

Search

Create a search client:

var ElasticSearchClient = require('elasticsearchclient'),
url = require('url');

var connectionString = url.parse(JSON.parse(process.env.VCAP_SERVICES)['searchly'][0]['credentials']['uri']);

var serverOptions = {
    host: connectionString.hostname,
    port: connectionString.port,
    secure: false,
    auth: {
        username: connectionString.auth.split(":")[0],
        password: connectionString.auth.split(":")[1]
    }
};

var elasticSearchClient = new ElasticSearchClient(serverOptions);

Index a document

elasticSearchClient.index('sample', 'document', {'name':'Reliability', 'text':'Reliability is improved', id:"1"})
    .on('data', function(data) {
        console.log(data)
    }).exec()

Create a query and search it

var qryObj = {
    "query":{
        "query_string":{
            "query":"Reliability"
        }
    }
};

elasticSearchClient.search('sample', 'document', qryObj)
    .on('data', function (data) {
            console.log(data)
    }).on('error', function (error) {
            console.log(error)
    }).exec()

Sample Applications

Dashboard

Though our dashboard, you can get your connection information and api-key, create access keys for scoping indices or public only accesses, check your limitation, create crawlers, and get graphical information of your search analytics.

Dashboard

Support

Contacting Service Providers for Support

External Links

Create a pull request or raise an issue on the source for this page in GitHub