2013-02-03 11:31:26 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Spring Data Elasticsearch
							 
						 
					
						
							
								
									
										
										
										
											2014-03-31 17:39:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								=========================
							 
						 
					
						
							
								
									
										
										
										
											2013-01-24 09:02:38 -08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Spring Data implementation for ElasticSearch
							 
						 
					
						
							
								
									
										
										
										
											2013-01-24 17:22:42 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Spring Data makes it easier to build Spring-powered applications that use new data access technologies such as non-relational databases, map-reduce frameworks, and cloud based data services as well as provide improved support for relational database technologies.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								The Spring Data Elasticsearch project provides integration with the [elasticsearch ](http://www.elasticsearch.org/ ) search engine.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Guide
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								------------
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-05-20 16:26:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  [Reference Documentation ](http://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/ ) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  [API Documentation ](http://docs.spring.io/spring-data/elasticsearch/docs/current/api/ ) 
						 
					
						
							
								
									
										
										
										
											2014-06-05 16:17:47 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  [Spring Data Project ](http://projects.spring.io/spring-data ) 
						 
					
						
							
								
									
										
										
										
											2013-04-11 12:29:59 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  [Sample Test Application ](https://github.com/BioMedCentralLtd/spring-data-elasticsearch-sample-application ) 
						 
					
						
							
								
									
										
										
										
											2016-03-11 12:04:14 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  [Issues ](https://jira.springsource.org/browse/DATAES ) 
						 
					
						
							
								
									
										
										
										
											2014-05-20 16:26:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  [Spring Data Elasticsearch Google Group ](https://groups.google.com/d/forum/spring-data-elasticsearch-devs ) 
						 
					
						
							
								
									
										
										
										
											2016-03-11 12:04:14 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  [Questions ](http://stackoverflow.com/questions/tagged/spring-data-elasticsearch ) 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Quick Start
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								-----------
							 
						 
					
						
							
								
									
										
										
										
											2014-05-20 16:26:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Wiki page for [Getting Started ](https://github.com/spring-projects/spring-data-elasticsearch/wiki/How-to-start-with-spring-data-elasticsearch )
							 
						 
					
						
							
								
									
										
										
										
											2013-09-09 17:24:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								### Maven configuration
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Add the Maven dependency:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```xml
							 
						 
					
						
							
								
									
										
										
										
											2013-02-03 11:31:26 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								< dependency >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    < groupId > org.springframework.data< / groupId > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    < artifactId > spring-data-elasticsearch< / artifactId > 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-10 10:23:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    < version > x.y.z.RELEASE< / version > 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								< / dependency >  
						 
					
						
							
								
									
										
										
										
											2013-02-03 11:33:39 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								If you'd rather like the latest snapshots of the upcoming major version, use our Maven snapshot repository and declare
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								the appropriate dependency version.
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								```xml
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								< dependency >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  < groupId > org.springframework.data< / groupId > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  < artifactId > spring-data-elasticsearch< / artifactId > 
							 
						 
					
						
							
								
									
										
										
										
											2016-11-10 10:23:19 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  < version > x.y.z.BUILD-SNAPSHOT< / version > 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								< / dependency >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								< repository >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  < id > spring-libs-snapshot< / id > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								  < name > Spring Snapshot Repository< / name > 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-31 17:39:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								  < url > http://repo.spring.io/libs-snapshot< / url > 
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								< / repository >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-02-25 09:44:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								|   spring data elasticsearch         | elasticsearch |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								|:-----------------------------------:|:-------------:|
							 
						 
					
						
							
								
									
										
										
										
											2017-07-26 11:58:24 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								|           3.0.0.RC2                 |      5.5.0    |
							 
						 
					
						
							
								
									
										
										
										
											2017-07-21 10:55:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								|           3.0.0.M4                  |      5.4.0    |
							 
						 
					
						
							
								
									
										
										
										
											2016-11-03 10:52:48 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								|           2.0.4.RELEASE             |      2.4.0    |
							 
						 
					
						
							
								
									
										
										
										
											2016-04-07 09:48:43 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								|           2.0.0.RELEASE             |      2.2.0    |
							 
						 
					
						
							
								
									
										
										
										
											2016-02-25 09:44:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								|           1.4.0.M1                  |      1.7.3    |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								|           1.3.0.RELEASE             |      1.5.2    |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								|           1.2.0.RELEASE             |      1.4.4    |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								|           1.1.0.RELEASE             |      1.3.2    |
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								|           1.0.0.RELEASE             |      1.1.1    |
							 
						 
					
						
							
								
									
										
										
										
											2014-10-19 10:54:50 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-07-10 13:19:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								### 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
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    public interface ElasticsearchCrudRepository< T ,  ID  extends  Serializable >  extends ElasticsearchRepository< T ,  ID > , PagingAndSortingRepository< T ,  ID >  {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Extending ElasticsearchRepository for custom methods
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```java
							 
						 
					
						
							
								
									
										
										
										
											2013-02-01 15:59:28 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    public interface BookRepository extends Repository< Book ,  String >  {
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-04-10 10:54:48 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        List< Book >  findByNameAndPrice(String name, Integer price);
							 
						 
					
						
							
								
									
										
										
										
											2013-04-10 10:52:51 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        List< Book >  findByNameOrPrice(String name, Integer price);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        Page< Book >  findByName(String name,Pageable page);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        Page< Book >  findByNameNot(String name,Pageable page);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        Page< Book >  findByPriceBetween(int price,Pageable page);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        Page< Book >  findByNameLike(String name,Pageable page);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        @Query ("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}")
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        Page< Book >  findByMessage(String message, Pageable pageable);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Indexing a single document with Repository
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```java
							 
						 
					
						
							
								
									
										
										
										
											2014-02-11 00:44:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        @Autowired 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        private SampleElasticsearchRepository repository;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        String documentId = "123456";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        SampleEntity sampleEntity = new SampleEntity();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity.setId(documentId);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity.setMessage("some message");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        repository.save(sampleEntity);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Indexing multiple Document(bulk index) using Repository
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```java
							 
						 
					
						
							
								
									
										
										
										
											2014-02-11 00:44:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        @Autowired 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        private SampleElasticsearchRepository repository;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        String documentId = "123456";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        SampleEntity sampleEntity1 = new SampleEntity();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity1.setId(documentId);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity1.setMessage("some message");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        String documentId2 = "123457"
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        SampleEntity sampleEntity2 = new SampleEntity();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity2.setId(documentId2);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity2.setMessage("test message");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        List< SampleEntity >  sampleEntities = Arrays.asList(sampleEntity1, sampleEntity2);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        //bulk index
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        repository.save(sampleEntities);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-11-17 22:04:04 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								### ElasticsearchTemplate
  
						 
					
						
							
								
									
										
										
										
											2013-11-17 22:04:04 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								ElasticsearchTemplate is the central support class for elasticsearch operations.
							 
						 
					
						
							
								
									
										
										
										
											2013-11-17 22:04:04 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Indexing a single document using Elasticsearch Template
							 
						 
					
						
							
								
									
										
										
										
											2013-11-17 22:04:04 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								```java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        String documentId = "123456";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        SampleEntity sampleEntity = new SampleEntity();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity.setId(documentId);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity.setMessage("some message");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        IndexQuery indexQuery = new IndexQueryBuilder().withId(sampleEntity.getId()).withObject(sampleEntity).build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        elasticsearchTemplate.index(indexQuery);
							 
						 
					
						
							
								
									
										
										
										
											2013-11-17 22:04:04 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Indexing multiple Document(bulk index) using Elasticsearch Template
							 
						 
					
						
							
								
									
										
										
										
											2013-11-06 14:52:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```java
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        @Autowired 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        private ElasticsearchTemplate elasticsearchTemplate;
							 
						 
					
						
							
								
									
										
										
										
											2013-11-06 14:52:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        List< IndexQuery >  indexQueries = new ArrayList< IndexQuery > ();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        //first document
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        String documentId = "123456";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        SampleEntity sampleEntity1 = new SampleEntity();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity1.setId(documentId);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity1.setMessage("some message");
							 
						 
					
						
							
								
									
										
										
										
											2013-11-06 14:52:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        IndexQuery indexQuery1 = new IndexQueryBuilder().withId(sampleEntity1.getId()).withObject(sampleEntity1).build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        indexQueries.add(indexQuery1);
							 
						 
					
						
							
								
									
										
										
										
											2013-11-06 14:52:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        //second document
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        String documentId2 = "123457";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        SampleEntity sampleEntity2 = new SampleEntity();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity2.setId(documentId2);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        sampleEntity2.setMessage("some message");
							 
						 
					
						
							
								
									
										
										
										
											2013-11-06 14:52:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        IndexQuery indexQuery2 = new IndexQueryBuilder().withId(sampleEntity2.getId()).withObject(sampleEntity2).build()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        indexQueries.add(indexQuery2);
							 
						 
					
						
							
								
									
										
										
										
											2013-11-06 14:52:38 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        //bulk index
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        elasticsearchTemplate.bulkIndex(indexQueries);
							 
						 
					
						
							
								
									
										
										
										
											2013-11-17 13:36:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Searching entities using Elasticsearch Template
							 
						 
					
						
							
								
									
										
										
										
											2013-11-17 13:36:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```java
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        @Autowired 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        private ElasticsearchTemplate elasticsearchTemplate;
							 
						 
					
						
							
								
									
										
										
										
											2013-11-17 13:36:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								        SearchQuery searchQuery = new NativeSearchQueryBuilder()
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        .withQuery(queryString(documentId).field("id"))
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        .build();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        Page< SampleEntity >  sampleEntities = elasticsearchTemplate.queryForPage(searchQuery,SampleEntity.class);
							 
						 
					
						
							
								
									
										
										
										
											2013-11-17 13:36:56 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								### XML Namespace
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								You can set up repository scanning via xml configuration, which will happily create your repositories.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 11:26:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								Using Node Client
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								```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"
							 
						 
					
						
							
								
									
										
										
										
											2014-05-20 16:26:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								       xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 10:05:24 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    < 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 >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 11:26:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Using Transport Client
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								```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"
							 
						 
					
						
							
								
									
										
										
										
											2014-05-20 16:26:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								       xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
										http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 11:26:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    < elasticsearch:repositories  base-package = "com.xyz.acme" / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								    < elasticsearch:transport-client  id = "client"  cluster-nodes = "ip:9300,ip:9300"  cluster-name = "elasticsearch"  / > 
							 
						 
					
						
							
								
									
										
										
										
											2013-01-28 11:26:55 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    < bean  name = "elasticsearchTemplate"  class = "org.springframework.data.elasticsearch.core.ElasticsearchTemplate" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								        < constructor-arg  name = "client"  ref = "client" / > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								    < / bean > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								< / beans >  
						 
					
						
							
								
									
										
										
										
											2014-03-04 19:17:57 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								## Help Pages
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  [Geo distance and location search ](https://github.com/spring-projects/spring-data-elasticsearch/wiki/Geo-indexing-and-request ) 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  [Custom object mapper ](https://github.com/spring-projects/spring-data-elasticsearch/wiki/Custom-ObjectMapper ) 
						 
					
						
							
								
									
										
										
										
											2013-02-06 16:23:32 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:24:30 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								## Contributing to Spring Data
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Here are some ways for you to get involved in the community:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-05-29 13:56:46 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  Get involved with the Spring community on Stack OverFlow.  Please help out on the [forum ](https://stackoverflow.com/questions/tagged/spring-data-elasticsearch ) by responding to questions and joining the debate. 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								*  Create [JIRA ](https://jira.spring.io/browse/DATAES/ ) tickets for bugs and new features and comment and vote on the ones that you are interested in.   
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:24:30 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								*  Github is for social coding: if you want to write code, we encourage contributions through pull requests from [forks of this repository ](http://help.github.com/forking/ ). 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 [subscribing ](http://www.springsource.org/node/feed ) to springframework.org 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-01-13 11:25:02 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
										 
							
							
								Before we accept a non-trivial patch or pull request we will need you to [sign the Contributor License Agreement ](https://cla.pivotal.io/sign/spring ). Signing the contributor’ 
							 
						 
					
						
							
								
									
										
										
										
											2014-01-04 18:24:30 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-02-11 00:44:03 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								Code formatting for [Eclipse and Intellij ](https://github.com/spring-projects/spring-data-build/tree/master/etc/ide )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
									
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-18 10:44:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
								
									
								 
							
							
								[More information about contributing to Spring Data ](https://github.com/spring-projects/spring-data-build/blob/master/CONTRIBUTING.adoc )