-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Allow to customize the mapped type name for @InnerField and @Field annotations #2950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -38,6 +38,7 @@ | |||||
* @author Morgan Lutz | ||||||
* @author Sascha Woo | ||||||
* @author Haibo Liu | ||||||
* @author Andriy Redko | ||||||
*/ | ||||||
@Retention(RetentionPolicy.RUNTIME) | ||||||
@Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.METHOD }) | ||||||
|
@@ -240,4 +241,11 @@ | |||||
* @since 5.1 | ||||||
*/ | ||||||
boolean storeEmptyValue() default true; | ||||||
|
||||||
/** | ||||||
* overrides the mapping field type which otherwise will be taken from corresponding {@link FieldType} | ||||||
* | ||||||
* @since 5.4 | ||||||
*/ | ||||||
String mappedName() default ""; | ||||||
|
String mappedName() default ""; | |
String mappedTypeName() default ""; |
to not confuse with the field name
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
* @author Brian Kimmig | ||
* @author Morgan Lutz | ||
* @author Haibo Liu | ||
* @author Andriy Redko | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.ANNOTATION_TYPE) | ||
|
@@ -171,4 +172,11 @@ | |
* @since 5.4 | ||
*/ | ||
KnnIndexOptions[] knnIndexOptions() default {}; | ||
|
||
/** | ||
* overrides the mapping field type which otherwise will be taken from corresponding {@link FieldType} | ||
|
||
* | ||
* @since 5.4 | ||
*/ | ||
String mappedName() default ""; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -69,6 +69,7 @@ | |||||
* @author Peter-Josef Meisch | ||||||
* @author Xiao Yu | ||||||
* @author Subhobrata Dey | ||||||
* @author Andriy Redko | ||||||
*/ | ||||||
public class MappingBuilder { | ||||||
|
||||||
|
@@ -175,7 +176,8 @@ protected String buildPropertyMapping(ElasticsearchPersistentEntity<?> entity, | |||||
.findAnnotation(org.springframework.data.elasticsearch.annotations.Document.class); | ||||||
var dynamicMapping = docAnnotation != null ? docAnnotation.dynamic() : null; | ||||||
|
||||||
mapEntity(objectNode, entity, true, "", false, FieldType.Auto, null, dynamicMapping, runtimeFields); | ||||||
final FieldType fieldType = FieldType.Auto; | ||||||
mapEntity(objectNode, entity, true, "", false, fieldType, fieldType.getMappedName(), null, dynamicMapping, runtimeFields); | ||||||
|
||||||
if (!excludeFromSource.isEmpty()) { | ||||||
ObjectNode sourceNode = objectNode.putObject(SOURCE); | ||||||
|
@@ -210,7 +212,7 @@ private void writeTypeHintMapping(ObjectNode propertiesNode) throws IOException | |||||
} | ||||||
|
||||||
private void mapEntity(ObjectNode objectNode, @Nullable ElasticsearchPersistentEntity<?> entity, | ||||||
boolean isRootObject, String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, | ||||||
boolean isRootObject, String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, String mappedName, | ||||||
|
boolean isRootObject, String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, String mappedName, | |
boolean isRootObject, String nestedObjectFieldName, boolean nestedOrObjectField, FieldType fieldType, String fieldTypemappedName, |
might be mistaken as as mapped name of the entity
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,7 @@ | |
* @author Brian Kimmig | ||
* @author Morgan Lutz | ||
* @author Haibo Liu | ||
* @author Andriy Redko | ||
*/ | ||
@SpringIntegrationTest | ||
public abstract class MappingBuilderIntegrationTests extends MappingContextBaseTests { | ||
|
@@ -77,6 +78,12 @@ void cleanup() { | |
operations.indexOps(IndexCoordinates.of(indexNameProvider.getPrefix() + "*")).delete(); | ||
} | ||
|
||
@Test | ||
public void shouldSupportAllTypes() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is not strictly related but |
||
IndexOperations indexOperations = operations.indexOps(EntityWithAllTypes.class); | ||
indexOperations.createWithMapping(); | ||
} | ||
|
||
@Test | ||
public void shouldNotFailOnCircularReference() { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a little clearer for me