Skip to content

Sorting by a InnerField from Multifield is no longer working #3081

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

Closed
grackeon opened this issue Mar 24, 2025 · 2 comments · Fixed by #3082
Closed

Sorting by a InnerField from Multifield is no longer working #3081

grackeon opened this issue Mar 24, 2025 · 2 comments · Fixed by #3082
Assignees
Labels
type: bug A general bug

Comments

@grackeon
Copy link

Hello, after trying to upgrade to the latest version 5.4.4 it seems that sorting by inner fields is no longer working at all. This change of behavior is caused by the adjustments made in #3074.

Until now we had the following part in a separate mapping.json with no annotations at all on the name property in our User class:

{
  "user": {
    "aliases": {},
    "mappings": {
      "properties": {
        [..]
        "name": {
          "type": "text",
          "fields": {
            "raw": {
              "type": "keyword"
            }
          },
          "analyzer": "autocomplete",
          "search_analyzer": "standard"
        },
       [..]

The inner field name.raw is used for sorting purposes only, like in repository.findAll(Sort.by("name.raw").
Now the added manipulation of sort parameters added in MappingElasticsearchConverter.updatePropertiesInFieldsSortAndSourceFilter removes the .raw part from the sort parameter, which causes the whole query to fail as text fields are not optimised for sorting and therefore the operation is disabled by default.

I already tried moving the field information from the mapping.json directly to the class like the following, which created the correct mapping during index recreation, but the sort manipulation is still happening as if the model is not aware of its own inner field:

@MultiField(
      mainField = @Field(type = FieldType.Text, analyzer = "autocomplete", searchAnalyzer = "standard"),
      otherFields = @InnerField(suffix = "raw", type = FieldType.Keyword))
String name;

Am I missing something or is there no way to sort by name.raw now in the latest version?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 24, 2025
@sothawo
Copy link
Collaborator

sothawo commented Mar 24, 2025

That is not correct, thanks for finding and reporting. When parsing a property path Spring Data Elasticsearch should not stop at the first unknown property - as it might come from an external defined mapping, but add these parts to the resulting path.

Considering multifield values would be even better (in addition to keeping unknown) I'll check how easy that is. NOthing we can get from the annotaion that would help - the inner field name needs to be specified in the sort as is.

@sothawo sothawo added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 24, 2025
@sothawo sothawo self-assigned this Mar 24, 2025
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Mar 24, 2025
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Mar 24, 2025
@sothawo sothawo added this to the 5.5 RC1 (2025.0.0) milestone Mar 24, 2025
sothawo added a commit that referenced this issue Mar 24, 2025
Original Pull Request #3082
Closes #3081

Signed-off-by: Peter-Josef Meisch <[email protected]>
(cherry picked from commit 1ae6301)
@sothawo
Copy link
Collaborator

sothawo commented Mar 24, 2025

implemented in main and backported to branches 5.4.x and 5.3.x

sothawo added a commit that referenced this issue Mar 31, 2025
Original Pull Request #3082
Closes #3081

Signed-off-by: Peter-Josef Meisch <[email protected]>
(cherry picked from commit 1ae6301)
(cherry picked from commit 394fb7a)
@sothawo sothawo marked this as a duplicate of #3086 Apr 2, 2025
@sothawo sothawo marked this as a duplicate of #3087 Apr 4, 2025
@sothawo sothawo marked this as a duplicate of #3092 Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants