mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-07-08 19:42:45 +00:00
DATAES-794 - MappingBuilder must not write empty mapping properties.
Original PR: #434
This commit is contained in:
parent
91f442bd2f
commit
16d8cc22d1
@ -313,6 +313,15 @@ public class MappingBuilder {
|
|||||||
private void addSingleFieldMapping(XContentBuilder builder, ElasticsearchPersistentProperty property,
|
private void addSingleFieldMapping(XContentBuilder builder, ElasticsearchPersistentProperty property,
|
||||||
Field annotation, boolean nestedOrObjectField) throws IOException {
|
Field annotation, boolean nestedOrObjectField) throws IOException {
|
||||||
|
|
||||||
|
// build the property json, if empty skip it as this is no valid mapping
|
||||||
|
XContentBuilder propertyBuilder = jsonBuilder().startObject();
|
||||||
|
addFieldMappingParameters(propertyBuilder, annotation, nestedOrObjectField);
|
||||||
|
propertyBuilder.endObject().close();
|
||||||
|
|
||||||
|
if ("{}".equals(propertyBuilder.getOutputStream().toString())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
builder.startObject(property.getFieldName());
|
builder.startObject(property.getFieldName());
|
||||||
addFieldMappingParameters(builder, annotation, nestedOrObjectField);
|
addFieldMappingParameters(builder, annotation, nestedOrObjectField);
|
||||||
builder.endObject();
|
builder.endObject();
|
||||||
|
@ -380,7 +380,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
|
|
||||||
// given
|
// given
|
||||||
String expected = "{\"properties\":{" + "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
String expected = "{\"properties\":{" + "\"id-property\":{\"type\":\"keyword\",\"index\":true},"
|
||||||
+ "\"circular-property\":{\"type\":\"object\",\"properties\":{\"id-property\":{}}}" + "}}";
|
+ "\"circular-property\":{\"type\":\"object\",\"properties\":{}}" + "}}";
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String mapping = getMappingBuilder().buildPropertyMapping(FieldNameEntity.CircularEntity.class);
|
String mapping = getMappingBuilder().buildPropertyMapping(FieldNameEntity.CircularEntity.class);
|
||||||
@ -438,19 +438,15 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
" \"storeTrue\": {\n" + //
|
" \"storeTrue\": {\n" + //
|
||||||
" \"store\": true\n" + //
|
" \"store\": true\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"storeFalse\": {},\n" + //
|
|
||||||
" \"indexTrue\": {},\n" + //
|
|
||||||
" \"indexFalse\": {\n" + //
|
" \"indexFalse\": {\n" + //
|
||||||
" \"index\": false\n" + //
|
" \"index\": false\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"coerceTrue\": {},\n" + //
|
|
||||||
" \"coerceFalse\": {\n" + //
|
" \"coerceFalse\": {\n" + //
|
||||||
" \"coerce\": false\n" + //
|
" \"coerce\": false\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"fielddataTrue\": {\n" + //
|
" \"fielddataTrue\": {\n" + //
|
||||||
" \"fielddata\": true\n" + //
|
" \"fielddata\": true\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"fielddataFalse\": {},\n" + //
|
|
||||||
" \"type\": {\n" + //
|
" \"type\": {\n" + //
|
||||||
" \"type\": \"integer\"\n" + //
|
" \"type\": \"integer\"\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
@ -476,15 +472,12 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
" \"type\": \"keyword\",\n" + //
|
" \"type\": \"keyword\",\n" + //
|
||||||
" \"doc_values\": false\n" + //
|
" \"doc_values\": false\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"ignoreMalformedFalse\": {},\n" + //
|
|
||||||
" \"ignoreMalformedTrue\": {\n" + //
|
" \"ignoreMalformedTrue\": {\n" + //
|
||||||
" \"ignore_malformed\": true\n" + //
|
" \"ignore_malformed\": true\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"indexPhrasesTrue\": {\n" + //
|
" \"indexPhrasesTrue\": {\n" + //
|
||||||
" \"index_phrases\": true\n" + //
|
" \"index_phrases\": true\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"indexPhrasesFalse\": {},\n" + //
|
|
||||||
" \"indexOptionsNone\": {},\n" + //
|
|
||||||
" \"indexOptionsPositions\": {\n" + //
|
" \"indexOptionsPositions\": {\n" + //
|
||||||
" \"index_options\": \"positions\"\n" + //
|
" \"index_options\": \"positions\"\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
@ -494,22 +487,18 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
" \"customIndexPrefixes\": {\n" + //
|
" \"customIndexPrefixes\": {\n" + //
|
||||||
" \"index_prefixes\":{\"min_chars\":1,\"max_chars\":10}" + //
|
" \"index_prefixes\":{\"min_chars\":1,\"max_chars\":10}" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"normsTrue\": {},\n" + //
|
|
||||||
" \"normsFalse\": {\n" + //
|
" \"normsFalse\": {\n" + //
|
||||||
" \"norms\": false\n" + //
|
" \"norms\": false\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"nullValueNotSet\": {},\n" + //
|
|
||||||
" \"nullValueSet\": {\n" + //
|
" \"nullValueSet\": {\n" + //
|
||||||
" \"null_value\": \"NULLNULL\"\n" + //
|
" \"null_value\": \"NULLNULL\"\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"positionIncrementGap\": {\n" + //
|
" \"positionIncrementGap\": {\n" + //
|
||||||
" \"position_increment_gap\": 42\n" + //
|
" \"position_increment_gap\": 42\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"similarityDefault\": {},\n" + //
|
|
||||||
" \"similarityBoolean\": {\n" + //
|
" \"similarityBoolean\": {\n" + //
|
||||||
" \"similarity\": \"boolean\"\n" + //
|
" \"similarity\": \"boolean\"\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
" \"termVectorDefault\": {},\n" + //
|
|
||||||
" \"termVectorWithOffsets\": {\n" + //
|
" \"termVectorWithOffsets\": {\n" + //
|
||||||
" \"term_vector\": \"with_offsets\"\n" + //
|
" \"term_vector\": \"with_offsets\"\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
@ -1018,6 +1007,7 @@ public class MappingBuilderTests extends MappingContextBaseTests {
|
|||||||
@Nullable @Field private String termVectorDefault;
|
@Nullable @Field private String termVectorDefault;
|
||||||
@Nullable @Field(termVector = TermVector.with_offsets) private String termVectorWithOffsets;
|
@Nullable @Field(termVector = TermVector.with_offsets) private String termVectorWithOffsets;
|
||||||
@Nullable @Field(type = FieldType.Scaled_Float, scalingFactor = 100.0) Double scaledFloat;
|
@Nullable @Field(type = FieldType.Scaled_Float, scalingFactor = 100.0) Double scaledFloat;
|
||||||
|
@Nullable @Field(type = Auto) String autoField;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Document(indexName = "test-index-configure-dynamic-mapping")
|
@Document(indexName = "test-index-configure-dynamic-mapping")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user