added support for dynamic mapping

(https://github.com/BioMedCentralLtd/spring-data-elasticsearch/issues/5)
This commit is contained in:
Rizwan Idrees
2013-03-22 12:34:38 +00:00
parent 33f506fb8c
commit cae34e5098
8 changed files with 280 additions and 3 deletions

View File

@@ -0,0 +1,71 @@
/*
* Copyright 2013 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;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
/**
* @author Rizwan Idrees
* @author Mohsin Husen
*/
@Document(indexName = "test-mapping", type = "mapping")
public class SampleMappingEntity {
@Id
private String id;
@Field(type = "string",index = "not_analyzed", store = true, searchAnalyzer = "standard", indexAnalyzer = "standard")
private String message;
private NestedEntity nested;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
static class NestedEntity{
@Field(type = "string")
private String someField;
public String getSomeField() {
return someField;
}
public void setSomeField(String someField) {
this.someField = someField;
}
}
}

View File

@@ -31,6 +31,7 @@ import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.elasticsearch.SampleEntity;
import org.springframework.data.elasticsearch.SampleMappingEntity;
import org.springframework.data.elasticsearch.core.query.*;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -612,4 +613,14 @@ public class ElasticsearchTemplateTest {
}
assertThat(sampleEntities.size(), is(equalTo(2)));
}
@Test
public void shouldPutMappingForGivenEntity()throws Exception{
//given
Class entity = SampleMappingEntity.class;
elasticsearchTemplate.createIndex(entity);
//when
assertThat(elasticsearchTemplate.putMapping(entity) , is(true)) ;
}
}

View File

@@ -417,5 +417,4 @@ public class RepositoryTest {
}
return sampleEntities;
}
}