DATAES-535 - Add mapping annotation @DynamicTemplates.
Original pull request: #238
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.elasticsearch.entities.SampleDynamicTemplatesEntity;
|
||||
import org.springframework.data.elasticsearch.entities.SampleDynamicTemplatesEntityTwo;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Dynamic templates tests
|
||||
*
|
||||
* @author Petr Kukral
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
public class SimpleDynamicTemplatesMappingTests {
|
||||
|
||||
@Test
|
||||
public void testCorrectDynamicTemplatesMappings() throws IOException {
|
||||
XContentBuilder xContentBuilder = MappingBuilder.buildMapping(SampleDynamicTemplatesEntity.class,
|
||||
"test-dynamictemplatestype", "id", null);
|
||||
String EXPECTED_MAPPING_ONE = "{\"test-dynamictemplatestype\":{\"dynamic_templates\":" +
|
||||
"[{\"with_custom_analyzer\":{" +
|
||||
"\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"}," +
|
||||
"\"path_match\":\"names.*\"}}]," +
|
||||
"\"properties\":{\"names\":{\"type\":\"object\"}}}}";
|
||||
Assert.assertEquals(EXPECTED_MAPPING_ONE, Strings.toString(xContentBuilder));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCorrectDynamicTemplatesMappingsTwo() throws IOException {
|
||||
XContentBuilder xContentBuilder = MappingBuilder.buildMapping(SampleDynamicTemplatesEntityTwo.class,
|
||||
"test-dynamictemplatestype", "id", null);
|
||||
String EXPECTED_MAPPING_TWO = "{\"test-dynamictemplatestype\":{\"dynamic_templates\":" +
|
||||
"[{\"with_custom_analyzer\":{" +
|
||||
"\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"}," +
|
||||
"\"path_match\":\"names.*\"}}," +
|
||||
"{\"participantA1_with_custom_analyzer\":{" +
|
||||
"\"mapping\":{\"type\":\"string\",\"analyzer\":\"standard_lowercase_asciifolding\"}," +
|
||||
"\"path_match\":\"participantA1.*\"}}]," +
|
||||
"\"properties\":{\"names\":{\"type\":\"object\"}}}}";
|
||||
Assert.assertEquals(EXPECTED_MAPPING_TWO, Strings.toString(xContentBuilder));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.DynamicTemplates;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
/**
|
||||
* @author Petr Kukral
|
||||
*/
|
||||
@Document(indexName = "test-dynamictemplates", type = "test-dynamictemplatestype", indexStoreType = "memory", shards = 1,
|
||||
replicas = 0, refreshInterval = "-1")
|
||||
@DynamicTemplates(mappingPath = "/mappings/test-dynamic_templates_mappings.json")
|
||||
public class SampleDynamicTemplatesEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(type = FieldType.Object)
|
||||
private Map<String, String> names = new HashMap<String, String>();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.DynamicTemplates;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
/**
|
||||
* @author Petr Kukral
|
||||
*/
|
||||
@Document(indexName = "test-dynamictemplates", type = "test-dynamictemplatestype", indexStoreType = "memory", shards = 1,
|
||||
replicas = 0, refreshInterval = "-1")
|
||||
@DynamicTemplates(mappingPath = "/mappings/test-dynamic_templates_mappings_two.json")
|
||||
public class SampleDynamicTemplatesEntityTwo {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(type = FieldType.Object)
|
||||
private Map<String, String> names = new HashMap<String, String>();
|
||||
}
|
||||
Reference in New Issue
Block a user