Compatible only with version 2.4. Enough for simple data storage functionality.
- spring-boot-starter-data-elasticsearch : 1.5.1.RELEASE
- org.springframework.data:spring-data-elasticsearch 2.1.0.RELEASE
- org.elasticsearch:elasticsearch 2.4.0
The simplest and cleanest way to set up client is with setting properties that are listed below. If for some reason this is not enough, client can be created with defining a ElasticsearchTemplate @Bean.
@Bean
public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
Settings settings = Settings.settingsBuilder().put("cluster.name", clusterName).build();
TransportClient client = TransportClient.builder().settings(settings).build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(clusterNodesHost),
clusterNodesPort));
return new ElasticsearchTemplate(client);
}
Appendix A contains list of properties
# ELASTICSEARCH (ElasticsearchProperties)
spring.data.elasticsearch.cluster-name=elasticsearch # Elasticsearch cluster name.
spring.data.elasticsearch.cluster-nodes= # Comma-separated list of cluster node addresses. If not specified, starts a client node.
spring.data.elasticsearch.properties.*= # Additional properties used to configure the client.
spring.data.elasticsearch.repositories.enabled=true # Enable Elasticsearch repositories.
docker pull elasticsearch:2.4-alpine
The NodeClient and the TranspotClient are basic Java clients. They can not be accessed by Perl, Python, Ruby etc. Link
The REST HTTP client exposes the NodeClient so that ES can be used by all languages who have a REST client. i.e. curl which listens at 9200.
Transport Client or Node Client that listens at 9300. The advantage of the TransportClient is that remote JVM can connect to ES cluster(s) over configurable network interface without becoming a full cluster node.
Number of documents:
curl -XGET 'url:9200/_count?pretty'
Check clusters:
curl -XGET 'url:9200/_cat/indices?v'
Check health:
curl -XGET 'url:9200/_cat/health?v'
Get document:
curl -XGET 'url:9200/{index}/{type}/{ID}?pretty'
Delete index:
curl -XDELETE 'url:9200/{index}?pretty'
Create index:
curl -XPUT 'url:9200/{index_name}?pretty'
Explicitly specify properties
curl -XPUT 'http://url:9200/articles?pretty' -H 'Content-Type: application/json' -d'
{
"settings" : {
"index" : {
"number_of_shards" : 5,
"number_of_replicas" : 1
}
}
}
'
List indices:
curl -XGET '172.17.0.2:9200/_cat/indices'
curl -XGET 'http://url:9200/_cat/health?v'
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1502975492 13:11:32 cluster-name red 3 1 0 0 0 0 12 0 - 0.0%
Status read tells us that the cluster is not healthy. We need to fix it.
bash-4.3# curl -XGET 'http://url:9200/_cat/indices'
red open index1 1 1
red open index2 5 1
We see that both indices are red
Recreation = delete index + create index
Check commands above.