Skip to content

Commit 66de262

Browse files
author
EmmanuelDuru
committed
Upgrade ES 6 (changing to single type indices + miscs for unit tests)
1 parent 1ec8cf1 commit 66de262

File tree

7 files changed

+19
-9
lines changed

7 files changed

+19
-9
lines changed

elasticsearch-mapping/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<groupId>org.elasticsearch.plugin</groupId>
2525
<artifactId>transport-netty4-client</artifactId>
2626
</dependency>
27+
<dependency>
28+
<groupId>org.codelibs.elasticsearch.module</groupId>
29+
<artifactId>analysis-common</artifactId>
30+
<version>${elasticsearch.version}</version>
31+
</dependency>
2732
<dependency>
2833
<groupId>com.floragunn</groupId>
2934
<artifactId>search-guard-ssl</artifactId>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.elasticsearch.action.admin.cluster.health.ClusterHealthAction;
1010
import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequestBuilder;
1111
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
12+
import org.elasticsearch.analysis.common.CommonAnalysisPlugin;
1213
import org.elasticsearch.client.Client;
1314
import org.elasticsearch.client.transport.TransportClient;
1415
import org.elasticsearch.common.network.NetworkModule;
@@ -86,10 +87,12 @@ public void initialize() throws Exception {
8687
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), "target/eshome")
8788
.put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME)
8889
.put(NetworkModule.HTTP_ENABLED.getKey(), false)
90+
.put("node.name", "alien")
8991
.put("cluster.name", this.clusterName)
9092
.build();
9193
ArrayList<Class<? extends Plugin>> plugins = new ArrayList<Class<? extends Plugin>>();
9294
plugins.add (MockTcpTransportPlugin.class);
95+
plugins.add (CommonAnalysisPlugin.class);
9396
MockNode node = new MockNode(settings, plugins);
9497
node.start();
9598
this.client = node.client();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ public void parseClassAnnotations(Class<?> clazz, String pathPrefix)
189189
List<IFacetBuilderHelper> facetFields = new ArrayList<IFacetBuilderHelper>();
190190
Map<String, SourceFetchContext> fetchContexts = new HashMap<String, SourceFetchContext>();
191191

192-
typeDefinitionMap.put(typeNameStr, classDefinitionMap);
192+
//typeDefinitionMap.put(typeNameStr, classDefinitionMap);
193+
typeDefinitionMap.put("_doc", classDefinitionMap);
193194

194195
/*********************
195196
if (esAll != null) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ public QueryBuilderHelper scriptFunction(String functionScore) {
314314
@Override
315315
public SearchResponse count(String[] indices, String... types) {
316316
SearchRequestBuilder countRequestBuilder = esClient.getClient().prepareSearch(indices);
317-
if (types != null && types.length > 0) {
317+
/**if (types != null && types.length > 0) {
318318
countRequestBuilder.setTypes(types);
319-
}
319+
}**/
320320
countRequestBuilder.setSize(0).setQuery(this.queryBuilder);
321321
return countRequestBuilder.execute().actionGet();
322322
}
@@ -465,7 +465,7 @@ private QueryBuilder getAndFilter(List<QueryBuilder> filters) {
465465

466466
@Override
467467
public SearchResponse execute(int from, int size) {
468-
searchRequestBuilder.setTypes(getTypes());
468+
//searchRequestBuilder.setTypes(getTypes());
469469
if (prefixField == null) {
470470
if (!fieldSort) {
471471
searchRequestBuilder.addSort(SortBuilders.scoreSort());

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ public void initIndexes(String indexName, Class<?>[] classes) throws Exception {
150150

151151
for (Class<?> clazz : classes) {
152152
System.out.println(mappingBuilder.getMapping(clazz));
153-
createIndexRequestBuilder.addMapping(clazz.getSimpleName().toLowerCase(), mappingBuilder.getMapping(clazz), XContentType.JSON);
153+
createIndexRequestBuilder.addMapping("_doc", mappingBuilder.getMapping(clazz), XContentType.JSON);
154+
//createIndexRequestBuilder.addMapping(clazz.getSimpleName().toLowerCase(), mappingBuilder.getMapping(clazz), XContentType.JSON);
154155
}
155156
final CreateIndexResponse createResponse = createIndexRequestBuilder.execute().actionGet();
156157
if (!createResponse.isAcknowledged()) {
@@ -165,11 +166,11 @@ public void save(String indexName, Person data) throws JsonGenerationException,
165166
System.out.println (json);
166167
//esClient.getClient().prepareIndex(indexName, indexName).setOperationThreaded(false).setSource(json).setRefresh(true).execute().actionGet();
167168
String idValue = (new FieldsMappingBuilder()).getIdValue(data);
168-
esClient.getClient().prepareIndex(indexName, indexName, idValue).setSource(json, XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE).execute().actionGet();
169+
esClient.getClient().prepareIndex(indexName, "_doc", idValue).setSource(json, XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE).execute().actionGet();
169170
}
170171

171172
public Person readById(String indexName, String id) throws JsonParseException, JsonMappingException, IOException {
172-
GetResponse response = esClient.getClient().prepareGet(indexName, indexName, id).execute().actionGet();
173+
GetResponse response = esClient.getClient().prepareGet(indexName, "_doc", id).execute().actionGet();
173174

174175
if (response == null || !response.isExists()) {
175176
return null;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"city":{"properties":{"all":{"type":"text"},"city":{"copy_to":"all","index":"true","boost":1.0,"store":false,"type":"keyword","fields":{"lower_case":{"fielddata":"true","analyzer":"lowerCaseAnalyser","index":"true","boost":1.0,"store":false,"type":"text"}}}}}}
1+
{"_doc":{"properties":{"all":{"type":"text"},"city":{"copy_to":"all","index":"true","boost":1.0,"store":false,"type":"keyword","fields":{"lower_case":{"fielddata":"true","analyzer":"lowerCaseAnalyser","index":"true","boost":1.0,"store":false,"type":"text"}}}}}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"person":{"properties":{"all":{"type":"text"},"firstname":{"index":"false","boost":1.0,"store":false,"type":"keyword"},"address":{"type":"nested","properties":{"city":{"index":"true","boost":1.0,"store":false,"type":"keyword"}}},"alienScore":{"index":"true","boost":1.0,"store":false,"ignore_malformed":false,"type":"long"},"addressMap":{"type":"object","enabled":"true","properties":{"value":{"properties":{"city":{"index":"true","boost":1.0,"store":false,"type":"keyword"}}},"key":{"copy_to":"all","index":"false","boost":1.0,"store":false,"type":"keyword"}}},"alternateAddress":{"type":"object","enabled":true,"properties":{"city":{"index":"true","boost":1.0,"store":false,"type":"keyword"}}},"lastname":{"copy_to":"all","fielddata":"true","index":"true","boost":1.0,"store":false,"type":"text"}}}}
1+
{"_doc":{"properties":{"all":{"type":"text"},"firstname":{"index":"false","boost":1.0,"store":false,"type":"keyword"},"address":{"type":"nested","properties":{"city":{"index":"true","boost":1.0,"store":false,"type":"keyword"}}},"alienScore":{"index":"true","boost":1.0,"store":false,"ignore_malformed":false,"type":"long"},"addressMap":{"type":"object","enabled":"true","properties":{"value":{"properties":{"city":{"index":"true","boost":1.0,"store":false,"type":"keyword"}}},"key":{"copy_to":"all","index":"false","boost":1.0,"store":false,"type":"keyword"}}},"alternateAddress":{"type":"object","enabled":true,"properties":{"city":{"index":"true","boost":1.0,"store":false,"type":"keyword"}}},"lastname":{"copy_to":"all","fielddata":"true","index":"true","boost":1.0,"store":false,"type":"text"}}}}

0 commit comments

Comments
 (0)