mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-31 09:12:11 +00:00
DATAES-589 - Improve readme file.
Original PR: #285, contains change from #268
This commit is contained in:
parent
42803ebd55
commit
2194096ad8
133
README.adoc
133
README.adoc
@ -2,7 +2,6 @@ image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-elasticsearch%2
|
||||
image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-elasticsearch%2F3.1.x&subject=Lovelace%20(3.1.x)[link=https://jenkins.spring.io/view/SpringData/job/spring-data-elasticsearch/]
|
||||
image:https://jenkins.spring.io/buildStatus/icon?job=spring-data-elasticsearch%2F2.1.x&subject=Ingalls%20(2.1.x)[link=https://jenkins.spring.io/view/SpringData/job/spring-data-elasticsearch/]
|
||||
|
||||
|
||||
= Spring Data Elasticsearch
|
||||
|
||||
Spring Data implementation for ElasticSearch
|
||||
@ -13,17 +12,31 @@ The Spring Data Elasticsearch project provides integration with the https://www.
|
||||
|
||||
== Guide
|
||||
|
||||
* https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/[Reference Documentation]
|
||||
* https://spring.io/projects/spring-data-elasticsearch#learn[Reference Documentation]
|
||||
* https://docs.spring.io/spring-data/elasticsearch/docs/current/api/[API Documentation]
|
||||
* https://projects.spring.io/spring-data[Spring Data Project]
|
||||
* https://spring.io/projects/spring-data[Spring Data Project]
|
||||
* https://jira.springsource.org/browse/DATAES[Issues (Spring Jira)]
|
||||
* https://stackoverflow.com/questions/tagged/spring-data-elasticsearch[Questions (Stack Overflow)]
|
||||
* https://github.com/BioMedCentralLtd/spring-data-elasticsearch-sample-application[Sample Test Application]
|
||||
* https://jira.springsource.org/browse/DATAES[Issues]
|
||||
* https://groups.google.com/d/forum/spring-data-elasticsearch-devs[Spring Data Elasticsearch Google Group]
|
||||
* https://stackoverflow.com/questions/tagged/spring-data-elasticsearch[Questions]
|
||||
|
||||
== Quick Start
|
||||
|
||||
Wiki page for https://github.com/spring-projects/spring-data-elasticsearch/wiki/How-to-start-with-spring-data-elasticsearch[Getting Started]
|
||||
This section is just short introduction, for more information refer to the https://spring.io/projects/spring-data-elasticsearch#learn[reference documentation].
|
||||
|
||||
=== Versions
|
||||
|
||||
The following table shows the Elasticsearch versions that are used by Spring Data Elasticsearch:
|
||||
[cols="^,^"]
|
||||
|===
|
||||
|Spring Data Elasticsearch |Elasticsearch
|
||||
|
||||
|3.2.x |6.7.2
|
||||
|3.1.x |6.2.2
|
||||
|3.0.x |5.5.0
|
||||
|2.1.x |2.4.0
|
||||
|2.0.x |2.2.0
|
||||
|1.3.x |1.5.2
|
||||
|===
|
||||
|
||||
=== Maven configuration
|
||||
|
||||
@ -56,35 +69,42 @@ the appropriate dependency version.
|
||||
</repository>
|
||||
----
|
||||
|
||||
[cols="^,^"]
|
||||
|===
|
||||
|spring data elasticsearch |elasticsearch
|
||||
|
||||
|3.2.x |6.5.0
|
||||
|3.1.x |6.2.2
|
||||
|3.0.x |5.5.0
|
||||
|2.1.x |2.4.0
|
||||
|2.0.x |2.2.0
|
||||
|1.3.x |1.5.2
|
||||
|===
|
||||
|
||||
=== ElasticsearchRepository
|
||||
|
||||
A default implementation of ElasticsearchRepository, aligning to the generic Repository Interfaces, is provided. Spring can do the Repository implementation for you depending on method names in the interface definition.
|
||||
|
||||
The ElasticsearchCrudRepository extends PagingAndSortingRepository
|
||||
A default implementation of `ElasticsearchRepository`, aligning to the generic `Repository` Interfaces, is provided. Spring can do the `Repository` implementation for you depending on method names in the interface definition.
|
||||
For a detailed information about Spring Data, repositories and the supported query methods check the https://spring.io/projects/spring-data-elasticsearch#learn[reference documentation].
|
||||
|
||||
[source,java]
|
||||
----
|
||||
public interface ElasticsearchCrudRepository<T, ID extends Serializable> extends ElasticsearchRepository<T, ID>, PagingAndSortingRepository<T, ID> {
|
||||
@NoRepositoryBean
|
||||
public interface ElasticsearchRepository<T, ID> extends ElasticsearchCrudRepository<T, ID> {
|
||||
|
||||
<S extends T> S index(S entity);
|
||||
|
||||
Iterable<T> search(QueryBuilder query);
|
||||
|
||||
Page<T> search(QueryBuilder query, Pageable pageable);
|
||||
|
||||
Page<T> search(SearchQuery searchQuery);
|
||||
|
||||
Page<T> searchSimilar(T entity, String[] fields, Pageable pageable);
|
||||
|
||||
void refresh();
|
||||
|
||||
Class<T> getEntityClass();
|
||||
}
|
||||
|
||||
@NoRepositoryBean
|
||||
public interface ElasticsearchCrudRepository<T, ID> extends PagingAndSortingRepository<T, ID> {
|
||||
}
|
||||
----
|
||||
|
||||
Extending ElasticsearchRepository for custom methods
|
||||
.Extending `ElasticsearchRepository` with custom methods:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
public interface BookRepository extends Repository<Book, String> {
|
||||
public interface BookRepository extends ElasticsearchRepository<Book, String> {
|
||||
|
||||
List<Book> findByNameAndPrice(String name, Integer price);
|
||||
|
||||
@ -103,7 +123,7 @@ Extending ElasticsearchRepository for custom methods
|
||||
}
|
||||
----
|
||||
|
||||
Indexing a single document with Repository
|
||||
.Indexing a single document using a `Repository`:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@ -118,7 +138,7 @@ Indexing a single document with Repository
|
||||
repository.save(sampleEntity);
|
||||
----
|
||||
|
||||
Indexing multiple Document(bulk index) using Repository
|
||||
.Indexing multiple documents (bulk index) using a `Repository`:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@ -141,11 +161,13 @@ Indexing multiple Document(bulk index) using Repository
|
||||
repository.save(sampleEntities);
|
||||
----
|
||||
|
||||
=== ElasticsearchTemplate
|
||||
=== ElasticsearchTemplate and ElasticsearchRestTemplate
|
||||
|
||||
ElasticsearchTemplate is the central support class for elasticsearch operations.
|
||||
`ElasticsearchTemplate` and `ElasticsearchRestTemplate` are the central support classes for Elasticsearch operations, both implement the `ElasticsearchOperations` interface that defines the methods to operate on an Elasticsearch cluster.
|
||||
|
||||
Indexing a single document using Elasticsearch Template
|
||||
`ElasticsearchTemplate` uses a `TransportClient`, whereas `ElasticsearchRestTemplate` uses the `RestHighLevelClient`. The `TransportClient` is deprecated in Elasticsearch 7, but until it is removed from Elasticsearch, the `ElasticsearchTemplate` will be supported as well.
|
||||
|
||||
.Indexing a single document using `ElasticsearchTemplate`:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@ -157,7 +179,7 @@ Indexing a single document using Elasticsearch Template
|
||||
elasticsearchTemplate.index(indexQuery);
|
||||
----
|
||||
|
||||
Indexing multiple Document(bulk index) using Elasticsearch Template
|
||||
.Indexing multiple documents (bulk index) using `ElasticsearchTemplate`:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@ -187,7 +209,7 @@ Indexing multiple Document(bulk index) using Elasticsearch Template
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
----
|
||||
|
||||
Searching entities using Elasticsearch Template
|
||||
.Searching entities using `ElasticsearchTemplate`:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@ -202,7 +224,7 @@ Searching entities using Elasticsearch Template
|
||||
|
||||
=== Reactive Elasticsearch
|
||||
|
||||
The `ReactiveElasticsearchClient` is a non official driver based on `WebClient`.
|
||||
The `ReactiveElasticsearchClient`, introduced in Spring Data Elasticsearch 3.2, is a non official driver based on `WebClient`.
|
||||
It uses the request/response objects provided by the Elasticsearch core project.
|
||||
|
||||
[source,java]
|
||||
@ -280,28 +302,7 @@ The above outputs the following sequence on the console.
|
||||
|
||||
You can set up repository scanning via xml configuration, which will happily create your repositories.
|
||||
|
||||
Using Node Client
|
||||
|
||||
[source,xml]
|
||||
----
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<elasticsearch:node-client id="client" local="true"/>
|
||||
|
||||
<bean name="elasticsearchTemplate" class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
||||
<constructor-arg name="client" ref="client"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
----
|
||||
|
||||
Using Transport Client
|
||||
|
||||
.Using TransportClient
|
||||
[source,xml]
|
||||
----
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
@ -322,6 +323,28 @@ Using Transport Client
|
||||
</beans>
|
||||
----
|
||||
|
||||
.Using RestClient
|
||||
[source,xml]
|
||||
----
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<elasticsearch:repositories base-package="com.xyz.acme"/>
|
||||
|
||||
<elasticsearch:rest-client id="restClient" hosts="http://localhost:9200"/>
|
||||
|
||||
<bean name="elasticsearchTemplate"
|
||||
class="org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate">
|
||||
<constructor-arg name="client" ref="restClient"/>
|
||||
</bean>
|
||||
|
||||
|
||||
</beans>
|
||||
----
|
||||
== Help Pages
|
||||
|
||||
* https://github.com/spring-projects/spring-data-elasticsearch/wiki/Geo-indexing-and-request[Geo distance and location search]
|
||||
@ -336,7 +359,7 @@ Here are some ways for you to get involved in the community:
|
||||
* Github is for social coding: if you want to write code, we encourage contributions through pull requests from https://help.github.com/forking/[forks of this repository]. If you want to contribute code this way, please reference a JIRA ticket as well covering the specific issue you are addressing.
|
||||
* Watch for upcoming articles on Spring by https://www.springsource.org/node/feed[subscribing] to springframework.org
|
||||
|
||||
Before we accept a non-trivial patch or pull request we will need you to https://cla.pivotal.io/sign/spring[sign the Contributor License Agreement]. Signing the contributor’s agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. If you forget to do so, you'll be reminded when you submit a pull request. Active contributors might be asked to join the core team, and given the ability to merge pull requests.
|
||||
Before we accept a pull request we will need you to https://cla.pivotal.io/sign/spring[sign the Contributor License Agreement]. Signing the contributor’s agreement does not grant anyone commit rights to the main repository, but it does mean that we can accept your contributions, and you will get an author credit if we do. If you forget to do so, you'll be reminded when you submit a pull request. Active contributors might be asked to join the core team, and given the ability to merge pull requests.
|
||||
|
||||
Code formatting for https://github.com/spring-projects/spring-data-build/tree/master/etc/ide[Eclipse and Intellij]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user