DATAES-492 - Add missing normalizer property to @Field and @InnerField.
Original pull request: #222
This commit is contained in:
@@ -47,6 +47,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
* @author Keivn Leturc
|
||||
* @author Nordine Bittich
|
||||
* @author Don Wellington
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
@@ -222,4 +223,25 @@ public class MappingBuilderTests {
|
||||
assertThat(descriptionMapping.get("type"), equalTo("text"));
|
||||
assertThat(descriptionMapping.get("analyzer"), equalTo("whitespace"));
|
||||
}
|
||||
|
||||
@Test // DATAES-492
|
||||
public void shouldUseKeywordNormalizer() throws IOException {
|
||||
|
||||
// given
|
||||
elasticsearchTemplate.deleteIndex(NormalizerEntity.class);
|
||||
elasticsearchTemplate.createIndex(NormalizerEntity.class);
|
||||
elasticsearchTemplate.putMapping(NormalizerEntity.class);
|
||||
|
||||
// when
|
||||
Map mapping = elasticsearchTemplate.getMapping(NormalizerEntity.class);
|
||||
Map properties = (Map) mapping.get("properties");
|
||||
Map fieldName = (Map) properties.get("name");
|
||||
Map fieldDescriptionLowerCase = (Map) ((Map) ((Map) properties.get("description")).get("fields")).get("lower_case");
|
||||
|
||||
// then
|
||||
assertThat(fieldName.get("type"), equalTo("keyword"));
|
||||
assertThat(fieldName.get("normalizer"), equalTo("lower_case_normalizer"));
|
||||
assertThat(fieldDescriptionLowerCase.get("type"), equalTo("keyword"));
|
||||
assertThat(fieldDescriptionLowerCase.get("normalizer"), equalTo("lower_case_normalizer"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
import org.springframework.data.elasticsearch.annotations.Setting;
|
||||
|
||||
/**
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "test-index-normalizer", type = "test", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Setting(settingPath = "/settings/test-normalizer.json")
|
||||
public class NormalizerEntity {
|
||||
|
||||
@Id private String id;
|
||||
|
||||
@Field(type = FieldType.Keyword, normalizer = "lower_case_normalizer")
|
||||
private String name;
|
||||
|
||||
@MultiField(mainField = @Field(type = FieldType.Text), otherFields = { @InnerField(suffix = "lower_case",
|
||||
type = FieldType.Keyword, normalizer = "lower_case_normalizer") })
|
||||
private String description;
|
||||
}
|
||||
Reference in New Issue
Block a user