Amdatu ElasticSearch

Project Info

Description

Amdatu Elasticsearch makes it possible to use the ElasticSearch Java client in OSGi.The ElasticSearch client can be used in the following ways (quoted from the ElasticSearch documenting):

You can use the Java client in multiple ways:

  • Perform standard indexgetdelete and search operations on an existing cluster
  • Perform administrative tasks on a running cluster
  • Start full nodes when you want to run Elasticsearch embedded in your own application or when you want to launch unit or integration tests

 

This means Amdatu ElasticSearch can be used to connect an OSGi application to an existing ElasticSearch cluster as a client, or embed ElasticSearch entirely in the application. The latter is mostly useful for testing purposes.

Components

BundleRequiredDescription
org.amdatu.elasticsearchyesContains the ElasticSearch client including all its dependencies. Note that the Java client can act as a full node, this explains the large number of dependencies that are required to be wrapped. There is currently no client-only Java driver available.

There seems to be a license issue in ElasticSearch itself: https://github.com/elasticsearch/elasticsearch/issues/2794. This affects the license of this component as well, because we now have dependency on a LGPLv2 licensed library, but can't be fixed until the issue is solved in ElasticSearch itself.

 

Configuration

All configuration properties supported by the Java client are passed through from ConfigurationAdmin to the client. These properties are not listed here, but can be found in the ElasticSearch documentation. There are some required properties however:

 

PropertyRequiredDescription
cluster.nameyesName of the cluster to create or connect to
node.nameyesThe name of the node within the cluster

 

Example

A fully working example can be found in the org.amdatu.elasticsearch.demo project. First download and start ElasticSearch. This will create a cluster "elasticsearch" and an example "bank" index. The following code can be used to query this index.

 

@Component(provides=Object.class, properties={
	@Property(name=CommandProcessor.COMMAND_SCOPE, value="search"),
	@Property(name=CommandProcessor.COMMAND_FUNCTION, value="query")
})
public class SearchCommands {
	
	@ServiceDependency
	private volatile Node m_node;
	
	public void query(String q) {
		SearchResponse response = m_node.client().prepareSearch("bank")
				.setQuery(QueryBuilders.multiMatchQuery(q, "firstname", "lastname"))
		        .execute()
		        .actionGet();
		
		for(SearchHit hit : response.getHits()) {
			System.out.println(hit.getSourceAsString());
		}
	}
}