DATAES-503 - Added missing copy_to property to @Field annotation.
Original pull request: #227
This commit is contained in:
@@ -24,6 +24,7 @@ import static org.springframework.data.elasticsearch.utils.IndexBuilder.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,11 +33,21 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.builder.SampleInheritedEntityBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.data.elasticsearch.entities.*;
|
||||
import org.springframework.data.elasticsearch.entities.Book;
|
||||
import org.springframework.data.elasticsearch.entities.CopyToEntity;
|
||||
import org.springframework.data.elasticsearch.entities.GeoEntity;
|
||||
import org.springframework.data.elasticsearch.entities.Group;
|
||||
import org.springframework.data.elasticsearch.entities.MinimalEntity;
|
||||
import org.springframework.data.elasticsearch.entities.NormalizerEntity;
|
||||
import org.springframework.data.elasticsearch.entities.SampleInheritedEntity;
|
||||
import org.springframework.data.elasticsearch.entities.SampleTransientEntity;
|
||||
import org.springframework.data.elasticsearch.entities.SimpleRecursiveEntity;
|
||||
import org.springframework.data.elasticsearch.entities.StockPrice;
|
||||
import org.springframework.data.elasticsearch.entities.User;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -244,4 +255,24 @@ public class MappingBuilderTests {
|
||||
assertThat(fieldDescriptionLowerCase.get("type"), equalTo("keyword"));
|
||||
assertThat(fieldDescriptionLowerCase.get("normalizer"), equalTo("lower_case_normalizer"));
|
||||
}
|
||||
|
||||
@Test // DATAES-503
|
||||
public void shouldUseCopyTo() throws IOException {
|
||||
|
||||
// given
|
||||
elasticsearchTemplate.deleteIndex(CopyToEntity.class);
|
||||
elasticsearchTemplate.createIndex(CopyToEntity.class);
|
||||
elasticsearchTemplate.putMapping(CopyToEntity.class);
|
||||
|
||||
// when
|
||||
Map mapping = elasticsearchTemplate.getMapping(CopyToEntity.class);
|
||||
Map properties = (Map) mapping.get("properties");
|
||||
Map fieldFirstName = (Map) properties.get("firstName");
|
||||
Map fieldLastName = (Map) properties.get("lastName");
|
||||
|
||||
// then
|
||||
List<String> copyToValue = Arrays.asList("name");
|
||||
assertThat(fieldFirstName.get("copy_to"), equalTo(copyToValue));
|
||||
assertThat(fieldLastName.get("copy_to"), equalTo(copyToValue));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* @author Sascha Woo
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "test-copy-to", type = "test", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class CopyToEntity {
|
||||
|
||||
@Id private String id;
|
||||
|
||||
@Field(type = FieldType.Keyword, copyTo = "name") private String firstName;
|
||||
|
||||
@Field(type = FieldType.Keyword, copyTo = "name") private String lastName;
|
||||
|
||||
@Field(type = FieldType.Keyword) private String name;
|
||||
}
|
||||
Reference in New Issue
Block a user