Skip to content

Commit 3e0e05d

Browse files
author
EmmanuelDuru
committed
Upgrade ES 5
1 parent 4f72a22 commit 3e0e05d

File tree

6 files changed

+32
-24
lines changed

6 files changed

+32
-24
lines changed

elasticsearch-mapping/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<groupId>org.elasticsearch.test</groupId>
115115
<artifactId>framework</artifactId>
116116
<version>${elasticsearch.version}</version>
117-
<scope>test</scope>
117+
<!--<scope>test</scope> -->
118118
<exclusions>
119119
<exclusion>
120120
<groupId>com.carrotsearch.randomizedtesting</groupId>

elasticsearch-mapping/src/main/java/org/elasticsearch/mapping/ElasticSearchClient.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.elasticsearch.mapping;
22

3+
import java.util.ArrayList;
34
import java.util.List;
45

56
import javax.annotation.PostConstruct;
@@ -10,9 +11,15 @@
1011
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
1112
import org.elasticsearch.client.Client;
1213
import org.elasticsearch.client.transport.TransportClient;
14+
import org.elasticsearch.common.network.NetworkModule;
1315
import org.elasticsearch.common.settings.Settings;
1416
import org.elasticsearch.common.transport.InetSocketTransportAddress;
1517
import org.elasticsearch.common.unit.TimeValue;
18+
import org.elasticsearch.env.Environment;
19+
import org.elasticsearch.node.MockNode;
20+
import org.elasticsearch.node.Node;
21+
import org.elasticsearch.plugins.Plugin;
22+
import org.elasticsearch.transport.MockTcpTransportPlugin;
1623
import org.elasticsearch.transport.client.PreBuiltTransportClient;
1724
import org.elasticsearch.util.AddressParserUtil;
1825
import org.springframework.beans.factory.annotation.Value;
@@ -32,7 +39,7 @@
3239
@Slf4j
3340
public class ElasticSearchClient {
3441

35-
// private Node node;
42+
private Node node;
3643
private boolean isClient;
3744
private boolean isTransportClient;
3845
private List<InetSocketTransportAddress> adresses;
@@ -47,7 +54,7 @@ public class ElasticSearchClient {
4754
private String truststorePassword = null;
4855

4956
@PostConstruct
50-
public void initialize() {
57+
public void initialize() throws Exception {
5158
if (this.isClient && this.isTransportClient) {
5259
// when these both option are set, we use a transport client
5360
Settings.Builder settingsBuilder = Settings.builder()
@@ -71,11 +78,21 @@ public void initialize() {
7178
}
7279
this.client = transportClient;
7380
} else {
74-
/************************
7581
// when only 'client' option is set, a node without data is initialized and joins the cluster
82+
/************************
7683
this.node = NodeBuilder.nodeBuilder().client(this.isClient).clusterName(this.clusterName).local(this.isLocal).node();
7784
this.client = node.client();
7885
***************************/
86+
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), "target/eshome")
87+
.put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME)
88+
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
89+
.build();
90+
ArrayList<Class<? extends Plugin>> plugins = new ArrayList<Class<? extends Plugin>>();
91+
plugins.add (MockTcpTransportPlugin.class);
92+
MockNode node = new MockNode(settings, plugins);
93+
node.start();
94+
this.client = node.client();
95+
this.node = node;
7996
}
8097

8198
// if (this.resetData) { // removes all indices from elastic search. For Integration testing only.
@@ -85,15 +102,13 @@ public void initialize() {
85102
}
86103

87104
@PreDestroy
88-
public void close() {
105+
public void close() throws Exception {
89106
if (client != null) {
90107
client.close();
91108
}
92-
/***
93109
if (node != null) {
94110
node.close();
95111
}
96-
****/
97112
log.info("Closed ElasticSearch client for cluster <" + this.clusterName + ">");
98113
}
99114

@@ -106,15 +121,6 @@ public Client getClient() {
106121
return this.client;
107122
}
108123

109-
/**
110-
* Set client (for tests)
111-
*
112-
* @param client ES client
113-
*/
114-
public void setClient (Client client) {
115-
this.client = client;
116-
}
117-
118124
/**
119125
* Wait for green status for the given indices.
120126
*

elasticsearch-mapping/src/main/java/org/elasticsearch/mapping/parser/BooleanFieldAnnotationParser.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.elasticsearch.annotation.BooleanField;
66
import org.elasticsearch.mapping.Indexable;
7+
import org.elasticsearch.mapping.IndexType;
78
import org.elasticsearch.mapping.MappingBuilder;
89
import lombok.extern.slf4j.Slf4j;
910

@@ -24,7 +25,8 @@ public void parseAnnotation(BooleanField annotation, Map<String, Object> fieldDe
2425

2526
fieldDefinition.put("type", "boolean");
2627
fieldDefinition.put("store", annotation.store());
27-
fieldDefinition.put("index", annotation.index());
28+
//fieldDefinition.put("index", annotation.index());
29+
fieldDefinition.put("index", annotation.index() == IndexType.no ? "false" : "true");
2830
fieldDefinition.put("boost", annotation.boost());
2931
fieldDefinition.put("include_in_all", annotation.includeInAll());
3032
}

elasticsearch-mapping/src/main/java/org/elasticsearch/mapping/parser/DateFieldAnnotationParser.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import org.elasticsearch.annotation.DateField;
66
import org.elasticsearch.mapping.Indexable;
7+
import org.elasticsearch.mapping.IndexType;
78
import org.elasticsearch.mapping.MappingBuilder;
89
import org.elasticsearch.mapping.MappingException;
910
import lombok.extern.slf4j.Slf4j;
@@ -25,8 +26,9 @@ public void parseAnnotation(DateField annotation, Map<String, Object> fieldDefin
2526

2627
fieldDefinition.put("type", "date");
2728
fieldDefinition.put("store", annotation.store());
28-
fieldDefinition.put("index", annotation.index());
29-
fieldDefinition.put("precision_step", annotation.precisionStep());
29+
//fieldDefinition.put("index", annotation.index());
30+
fieldDefinition.put("index", annotation.index() == IndexType.no ? "false" : "true");
31+
//fieldDefinition.put("precision_step", annotation.precisionStep());
3032
fieldDefinition.put("boost", annotation.boost());
3133
fieldDefinition.put("include_in_all", annotation.includeInAll());
3234
fieldDefinition.put("ignore_malformed", annotation.ignoreMalformed());

elasticsearch-mapping/src/test/java/org/elasticsearch/mapping/ElasticSearchInsertMappingTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class ElasticSearchInsertMappingTest {
5656

5757
@Before
5858
public void setUp() throws Exception {
59+
/***************
5960
try {
6061
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), "target/eshome")
6162
.put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME)
@@ -68,14 +69,11 @@ public void setUp() throws Exception {
6869
node.start();
6970
client = node.client();
7071
esClient.setClient(client);
71-
/***
72-
super.setUp();
73-
esClient.setClient(client());
74-
***/
7572
} catch (Exception e) {
7673
System.out.println ("Got " + e.getMessage());
7774
e.printStackTrace();
7875
}
76+
***********************/
7977
}
8078

8179
@Test

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
<groupId>org.elasticsearch.test</groupId>
104104
<artifactId>framework</artifactId>
105105
<version>${elasticsearch.version}</version>
106-
<scope>test</scope>
106+
<!-- <scope>test</scope> -->
107107
<exclusions>
108108
<exclusion>
109109
<groupId>com.carrotsearch.randomizedtesting</groupId>

0 commit comments

Comments
 (0)