Skip to content

Commit 4f72a22

Browse files
author
EmmanuelDuru
committed
Upgrade ES 5
1 parent 00f00c3 commit 4f72a22

File tree

9 files changed

+45
-15
lines changed

9 files changed

+45
-15
lines changed

elasticsearch-annotations/src/main/java/org/elasticsearch/mapping/IndexType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
*/
66
public enum IndexType {
77
analyzed, not_analyzed, no;
8-
}
8+
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,21 @@ public void parseAnnotation(MapKeyValue annotation, Map<String, Object> fieldDef
4343
Map<String, Object> keyFieldDefinition = Maps.newHashMap();
4444
properties.put("key", keyFieldDefinition);
4545

46-
keyFieldDefinition.put("type", "string");
46+
if (annotation.indexType() == IndexType.analyzed) {
47+
keyFieldDefinition.put("type", "text");
48+
keyFieldDefinition.put("index", "true");
49+
} else if (annotation.indexType() == IndexType.not_analyzed) {
50+
keyFieldDefinition.put("type", "keyword");
51+
keyFieldDefinition.put("index", "true");
52+
} else { // no
53+
keyFieldDefinition.put("type", "keyword");
54+
keyFieldDefinition.put("index", "false");
55+
}
56+
//keyFieldDefinition.put("type", "string");
4757
keyFieldDefinition.put("store", annotation.store());
48-
keyFieldDefinition.put("index", annotation.indexType());
58+
//keyFieldDefinition.put("index", annotation.indexType());
4959
// TODO doc_values
50-
keyFieldDefinition.put("term_vector", annotation.termVector());
60+
//keyFieldDefinition.put("term_vector", annotation.termVector());
5161
keyFieldDefinition.put("boost", annotation.boost());
5262
if (!StringField.NULL_VALUE_NOT_SPECIFIED.equals(annotation.nullValue())) {
5363
keyFieldDefinition.put("null_value", annotation.nullValue());

elasticsearch-mapping/src/main/java/org/elasticsearch/mapping/parser/NumberFieldAnnotationParser.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.NumberField;
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;
@@ -36,8 +37,9 @@ public void parseAnnotation(NumberField annotation, Map<String, Object> fieldDef
3637

3738
fieldDefinition.put("type", type);
3839
fieldDefinition.put("store", annotation.store());
39-
fieldDefinition.put("index", annotation.index());
40-
fieldDefinition.put("precision_step", annotation.precisionStep());
40+
//fieldDefinition.put("index", annotation.index());
41+
fieldDefinition.put("index", annotation.index() == IndexType.no ? "false" : "true");
42+
// removed in ES 5 : fieldDefinition.put("precision_step", annotation.precisionStep());
4143
fieldDefinition.put("boost", annotation.boost());
4244
fieldDefinition.put("include_in_all", annotation.includeInAll());
4345
fieldDefinition.put("ignore_malformed", annotation.ignoreMalformed());

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ public void parseAnnotation(StringField annotation, Map<String, Object> fieldDef
2222
fieldDefinition.clear();
2323
}
2424

25-
fieldDefinition.put("type", "string");
25+
if (annotation.indexType() == IndexType.analyzed) {
26+
fieldDefinition.put("type", "text");
27+
fieldDefinition.put("index", "true");
28+
} else if (annotation.indexType() == IndexType.not_analyzed) {
29+
fieldDefinition.put("type", "keyword");
30+
fieldDefinition.put("index", "true");
31+
} else { // no
32+
fieldDefinition.put("type", "keyword");
33+
fieldDefinition.put("index", "false");
34+
}
35+
//fieldDefinition.put("type", "string");
2636
fieldDefinition.put("store", annotation.store());
27-
fieldDefinition.put("index", annotation.indexType());
37+
//fieldDefinition.put("index", annotation.indexType());
2838
// TODO doc_values
29-
fieldDefinition.put("term_vector", annotation.termVector());
39+
//fieldDefinition.put("term_vector", annotation.termVector());
3040
fieldDefinition.put("boost", annotation.boost());
3141
if (!StringField.NULL_VALUE_NOT_SPECIFIED.equals(annotation.nullValue())) {
3242
fieldDefinition.put("null_value", annotation.nullValue());

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.elasticsearch.action.search.SearchRequestBuilder;
1818
import org.elasticsearch.action.search.SearchResponse;
1919
import org.elasticsearch.action.search.SearchType;
20+
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
2021
import com.google.common.collect.Maps;
2122
import org.elasticsearch.common.network.NetworkModule;
2223
import org.elasticsearch.common.settings.Settings;
@@ -97,6 +98,7 @@ public void testMappingAndInsert() throws Exception {
9798
save(indexName, person);
9899

99100
person.setId("AnotherPersonId");
101+
person.setLastname("something else");
100102
address.setCity("Paris");
101103
save(indexName, person);
102104

@@ -115,6 +117,12 @@ public void testMappingAndInsert() throws Exception {
115117

116118
response = this.queryHelper.buildQuery().types(requestedTypes).filters(filters).prepareSearch(searchIndexes).execute(0, 10000);
117119
Assert.assertEquals(2, response.getHits().getTotalHits());
120+
121+
filters.put("lastname", new String[] { "lastname" });
122+
response = this.queryHelper.buildQuery().types(requestedTypes).filters(filters).prepareSearch(searchIndexes).execute(0, 10000);
123+
Assert.assertEquals(1, response.getHits().getTotalHits());
124+
125+
filters = Maps.newHashMap();
118126
filters.put("address.city", new String[] { "Paris" });
119127
response = this.queryHelper.buildQuery().types(requestedTypes).filters(filters).prepareSearch(searchIndexes).execute(0, 10000);
120128
Assert.assertEquals(1, response.getHits().getTotalHits());
@@ -158,8 +166,7 @@ public void save(String indexName, Person data) throws JsonGenerationException,
158166
System.out.println (json);
159167
//esClient.getClient().prepareIndex(indexName, indexName).setOperationThreaded(false).setSource(json).setRefresh(true).execute().actionGet();
160168
String idValue = (new FieldsMappingBuilder()).getIdValue(data);
161-
162-
esClient.getClient().prepareIndex(indexName, indexName, idValue).setSource(json).setRefreshPolicy("IMMEDIATE").execute().actionGet();
169+
esClient.getClient().prepareIndex(indexName, indexName, idValue).setSource(json).setRefreshPolicy(RefreshPolicy.IMMEDIATE).execute().actionGet();
163170
}
164171

165172
public Person readById(String indexName, String id) throws JsonParseException, JsonMappingException, IOException {

elasticsearch-mapping/src/test/java/org/elasticsearch/mapping/model/Address.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ public String getCity() {
1616
public void setCity(String city) {
1717
this.city = city;
1818
}
19-
}
19+
}

elasticsearch-mapping/src/test/java/org/elasticsearch/mapping/model/Person.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class Person {
1717
private String id;
1818
@StringField(indexType = IndexType.no, includeInAll = false)
1919
private String firstname;
20+
@TermFilter
2021
@StringField(indexType = IndexType.analyzed)
2122
private String lastname;
2223

@@ -87,4 +88,4 @@ public Map<String, Address> getAddressMap() {
8788
public void setAddressMap(Map<String, Address> addressMap) {
8889
this.addressMap = addressMap;
8990
}
90-
}
91+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"city":{"_source":{"enabled":true},"_all":{"enabled":true},"properties":{"city":{"include_in_all":true,"term_vector":"no","index":"not_analyzed","boost":1.0,"store":false,"type":"string","fields":{"lower_case":{"include_in_all":false,"analyzer":"lowerCaseAnalyser","term_vector":"no","index":"analyzed","boost":1.0,"store":false,"type":"string"}}}}}}
1+
{"city":{"_source":{"enabled":true},"_all":{"enabled":true},"properties":{"city":{"include_in_all":true,"index":"true","boost":1.0,"store":false,"type":"keyword","fields":{"lower_case":{"include_in_all":false,"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":{"_source":{"enabled":true},"_all":{"analyzer":"simple","store":false,"enabled":true},"properties":{"firstname":{"include_in_all":false,"term_vector":"no","index":"no","boost":1.0,"store":false,"type":"string"},"address":{"type":"nested","properties":{"city":{"include_in_all":false,"term_vector":"no","index":"not_analyzed","boost":1.0,"store":false,"type":"string"}}},"alienScore":{"include_in_all":false,"precision_step":4,"index":"not_analyzed","boost":1.0,"store":false,"ignore_malformed":false,"type":"long"},"addressMap":{"type":"object","enabled":"true","properties":{"value":{"properties":{"city":{"include_in_all":false,"term_vector":"no","index":"not_analyzed","boost":1.0,"store":false,"type":"string"}}},"key":{"include_in_all":true,"term_vector":"no","index":"no","boost":1.0,"store":false,"type":"string"}}},"alternateAddress":{"type":"object","enabled":true,"properties":{"city":{"include_in_all":false,"term_vector":"no","index":"not_analyzed","boost":1.0,"store":false,"type":"string"}}},"lastname":{"include_in_all":true,"term_vector":"no","index":"analyzed","boost":1.0,"store":false,"type":"string"}}}}
1+
{"person":{"_source":{"enabled":true},"_all":{"analyzer":"simple","store":false,"enabled":true},"properties":{"firstname":{"include_in_all":false,"index":"false","boost":1.0,"store":false,"type":"keyword"},"address":{"type":"nested","properties":{"city":{"include_in_all":false,"index":"true","boost":1.0,"store":false,"type":"keyword"}}},"alienScore":{"include_in_all":false,"index":"true","boost":1.0,"store":false,"ignore_malformed":false,"type":"long"},"addressMap":{"type":"object","enabled":"true","properties":{"value":{"properties":{"city":{"include_in_all":false,"index":"true","boost":1.0,"store":false,"type":"keyword"}}},"key":{"include_in_all":true,"index":"false","boost":1.0,"store":false,"type":"keyword"}}},"alternateAddress":{"type":"object","enabled":true,"properties":{"city":{"include_in_all":false,"index":"true","boost":1.0,"store":false,"type":"keyword"}}},"lastname":{"include_in_all":true,"index":"true","boost":1.0,"store":false,"type":"text"}}}}

0 commit comments

Comments
 (0)