Skip to content
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

Add support for field mappings containing dots #2502

Closed
olada opened this issue Mar 21, 2023 · 4 comments · Fixed by #2504
Closed

Add support for field mappings containing dots #2502

olada opened this issue Mar 21, 2023 · 4 comments · Fixed by #2504
Assignees
Labels
status: worked on a contributor is working on this issue type: enhancement A general enhancement

Comments

@olada
Copy link

olada commented Mar 21, 2023

Elastic supports storing values in fields which contain dots (e.g. "foo.bar") (see elastic/elasticsearch#15951).

Unfortunately, spring-data-elasticsearch does not seem to support mapping such dot-containing field values using the @Field-annotation.

Cause is following lines:

if (!fieldName.contains(".")) {
return target.get(fieldName);
}

The dot "." is (understandably) used for navigating the object graph.
Unfortunately the @Field-annotation does not allow overriding such behaviour (e.g. with a "navigateObjectGraphUsingDot=false" parameter or something similar).

Steps to reproduce:

  • Store document containing a field which contains a dot (e.g. "foo.bar")
  • Create document mapping using spring-data-elasticsearch using @field("foo.bar")
  • Read documents with a repository

Behaviour:
The value of the entity which is mapped with @field("foo.bar") is null and does not contain the actual value from the elastic document

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 21, 2023
@sothawo sothawo self-assigned this Mar 22, 2023
@sothawo
Copy link
Collaborator

sothawo commented Mar 22, 2023

I'll have to check if this might conflict with logic from spring-data-commons.

@sothawo sothawo added type: enhancement A general enhancement status: worked on a contributor is working on this issue and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 22, 2023
sothawo added a commit that referenced this issue Mar 22, 2023
Original Pull Request #2504
Closes #2502
@sothawo sothawo added this to the 5.1 RC1 (2023.0.0) milestone Mar 22, 2023
@sothawo
Copy link
Collaborator

sothawo commented Mar 22, 2023

details in the pull request description

@olada
Copy link
Author

olada commented Mar 22, 2023

Hi @sothawo,

thanks for the super fast fix!

Can you explain how to differ between navigating the object graph using dot-notation vs direct field access for a dotted field?
I would've expected an additional property within the @Field-annotation - but the value for hasExplicitFieldName is automatically derived.

Thanks in advance!

@sothawo
Copy link
Collaborator

sothawo commented Mar 23, 2023

An ElasticsearchPersistentProperty has basically two names: the property name, which is the name used in the Java object, and the fieldname which is used in Elasticsearch. Normally they are the same, but there also could be a FieldNamingStrategy be set in the configuration (camel-case or snake-case). And there is the name attribute in the @Field annotation which explicitly defines a name that overrides the other ways to get the field name.

This fieldname is used at multiple places:

  • when writing the index mapping
  • when converting an entity into the document representation for Elasticsearch
  • when reading from Elasticsearch to the entity
  • when a CriteriaQuery is preprocessed. Criteria uses the entity property names and they must be mapped.

For StringQuerys and NativeQuerys this prepocessing is not possible, here the user must use the fieldname directly.

Navigating the object graph is done by Spring Data on method name resolution and that needs the Java property names, so no conflict here, under the hood this builds a CriteriaQuery which can be processed to have the filednames set.

So the explicit field name is not used anywhere where object property trees are considered.

What does not work of course is reading a nested structure coming from Elasticsearch into properties with dotted field names. For this you'd still need a nested object structure as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: worked on a contributor is working on this issue type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants