Skip to content

Commit d8162db

Browse files
committed
OperationDocument example
1 parent 488246a commit d8162db

File tree

6 files changed

+171
-1
lines changed

6 files changed

+171
-1
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<dependency>
8383
<groupId>org.springframework.data</groupId>
8484
<artifactId>spring-data-elasticsearch</artifactId>
85-
<version>1.0.0.M2</version>
85+
<version>1.2.0.RELEASE</version>
8686
</dependency>
8787
<dependency>
8888
<groupId>org.springframework</groupId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package org.springframework.data.elasticsearch.entities;
2+
3+
import java.util.Date;
4+
import java.util.List;
5+
6+
import org.springframework.data.annotation.Id;
7+
import org.springframework.data.elasticsearch.annotations.*;
8+
9+
/**
10+
* Created by mohsinhusen on 10/04/15.
11+
*/
12+
@Document(indexName = "operations", type = "operation")
13+
public class OperationDocument {
14+
15+
@Id
16+
private Long id;
17+
18+
@Field(
19+
type = FieldType.String,
20+
index = FieldIndex.analyzed,
21+
searchAnalyzer = "standard",
22+
indexAnalyzer = "standard",
23+
store = true
24+
)
25+
private String operationName;
26+
27+
@Field(
28+
type = FieldType.Date,
29+
index = FieldIndex.not_analyzed,
30+
store = true,
31+
format = DateFormat.custom, pattern = "dd.MM.yyyy hh:mm"
32+
)
33+
private Date dateUp;
34+
35+
@Field(
36+
type = FieldType.String,
37+
index = FieldIndex.not_analyzed,
38+
store = false
39+
)
40+
private String someTransientData;
41+
42+
@Field(type = FieldType.Nested)
43+
private List<Sector> sectors;
44+
45+
public Long getId() {
46+
return id;
47+
}
48+
49+
public void setId(Long id) {
50+
this.id = id;
51+
}
52+
53+
public String getOperationName() {
54+
return operationName;
55+
}
56+
57+
public void setOperationName(String operationName) {
58+
this.operationName = operationName;
59+
}
60+
61+
public Date getDateUp() {
62+
return dateUp;
63+
}
64+
65+
public void setDateUp(Date dateUp) {
66+
this.dateUp = dateUp;
67+
}
68+
69+
public String getSomeTransientData() {
70+
return someTransientData;
71+
}
72+
73+
public void setSomeTransientData(String someTransientData) {
74+
this.someTransientData = someTransientData;
75+
}
76+
77+
public List<Sector> getSectors() {
78+
return sectors;
79+
}
80+
81+
public void setSectors(List<Sector> sectors) {
82+
this.sectors = sectors;
83+
}
84+
}
85+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.springframework.data.elasticsearch.entities;
2+
3+
/**
4+
* Created by mohsinhusen on 10/04/15.
5+
*/
6+
public class Sector {
7+
8+
private int id;
9+
private String sectorName;
10+
11+
public int getId() {
12+
return id;
13+
}
14+
15+
public void setId(int id) {
16+
this.id = id;
17+
}
18+
19+
public String getSectorName() {
20+
return sectorName;
21+
}
22+
23+
public void setSectorName(String sectorName) {
24+
this.sectorName = sectorName;
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.springframework.data.elasticsearch.repositories;
2+
3+
import org.springframework.data.elasticsearch.entities.OperationDocument;
4+
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
5+
6+
/**
7+
* Created by mohsinhusen on 10/04/15.
8+
*/
9+
public interface OperationDocumentRepository extends ElasticsearchRepository<OperationDocument, Long> {
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.springframework.data.elasticsearch.repositories;
2+
3+
import java.util.Map;
4+
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
9+
import org.springframework.data.elasticsearch.entities.OperationDocument;
10+
import org.springframework.test.context.ContextConfiguration;
11+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
12+
13+
@RunWith(SpringJUnit4ClassRunner.class)
14+
@ContextConfiguration("classpath:/spring-context.xml")
15+
public class OperationDocumentRepositoryTest {
16+
17+
@Autowired
18+
private ElasticsearchTemplate elasticsearchTemplate;
19+
20+
@Autowired
21+
private OperationDocumentRepository repository;
22+
23+
@Test
24+
public void test() {
25+
Map mapping = elasticsearchTemplate.getMapping(OperationDocument.class);
26+
System.out.println(mapping.toString());
27+
}
28+
29+
30+
}

src/test/resources/spring-context.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
5+
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
6+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
7+
8+
<elasticsearch:transport-client id="client" cluster-name="elasticsearch" cluster-nodes="127.0.0.1:9301" />
9+
10+
<!--<elasticsearch:transport-client id="client" cluster-name="elasticsearch" cluster-nodes="127.0.0.1:9300"/>-->
11+
<bean name="elasticsearchTemplate" class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
12+
<constructor-arg name="client" ref="client"/>
13+
</bean>
14+
15+
16+
<elasticsearch:repositories base-package="org.springframework.data.elasticsearch.repositories" />
17+
18+
</beans>

0 commit comments

Comments
 (0)