Amdatu ElasticSearch
Project Info
What | Where |
---|---|
Main website | http://www.amdatu.org/components/elasticsearch.html |
Source code | https://bitbucket.org/amdatu/amdatu-elasticsearch |
Issue tracking | https://amdatu.atlassian.net/browse/AMDATUES |
Continuous build | https://amdatu.atlassian.net/builds/browse/AMDATUELASTICSEARCH |
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:
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
Bundle | Required | Description |
---|---|---|
org.amdatu.elasticsearch | yes | Contains 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:
Property | Required | Description |
---|---|---|
cluster.name | yes | Name of the cluster to create or connect to |
node.name | yes | The 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()); } } }