Skip to content

No mapping found for [###] in order to sort on #3072

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
mrboros opened this issue Mar 4, 2025 · 10 comments · Fixed by #3074
Closed

No mapping found for [###] in order to sort on #3072

mrboros opened this issue Mar 4, 2025 · 10 comments · Fixed by #3074
Assignees
Labels
type: bug A general bug

Comments

@mrboros
Copy link

mrboros commented Mar 4, 2025

Hello guys!

First and foremost, thanks for this awesome addition to the Spring ecosystem! I have a problem, though:
Here's an excerpt from an Elasticsearch document:

{
  "loglevel": "TRACE",
  "monitoring_event": {
    "type": "foo",
    "transaction_id": "baz",
    "monitoring_datetime": "2025-03-04T15:39:45.144"
  }
}

Here's my Java POJO for this document:

@Data
@Document(indexName = "foo-index")
public class FooEvent
{
    @Id
    private String id;

    @Field(name = "monitoring_event", type = FieldType.Object)
    private MonitoringEvent monitoringEvent;

    @Field("loglevel", type = FieldType.Keyword)
    private String loglevel;
}

@Data
class MonitoringEvent {
    @Field(name = "type", type = FieldType.Keyword)
    private String type;

    @Field(name = "transaction_id", type = FieldType.Keyword)
    private String transactionId;

    @Field(name = "monitoring_datetime", type = FieldType.Date, format = strict_date_optional_time_nanos)
    private LocalDateTime monitoringDatetime;
)

Here's my repository:

public interface FooRepository extends ElasticsearchRepository<FooEvent, String> {
    List<FooEvent> findByMonitoringEvent_TransactionIdOrderByMonitoringEvent_monitoringDatetime(String transactionId);
}

When invoking the method, the following error occurs: No mapping found for [monitoringEvent.monitoringDatetime] in order to sort on. So the problem is around the OrderBy clause of the repo method.

The sort clause of the underlying REST query is: "sort":[{"monitoringEvent.monitoringDatetime":{"mode":"min","order":"asc"}}]

The error is that monitoringEvent does not exist in Elasticsearch document, only monitoring_event. Am I doing something wrong (missing config, annotation, etc), or it is indeed a bug? The sort param should be in the same form as at the annotated @Field name parameter, so, in this case, monitoring_event.monitoring_datetime.

Thanks in advance for any replies.
regards,
Daniel

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

sothawo commented Mar 4, 2025

This indeed should not be; I'll have to try this locally, but I might not find the time until the weekend.

@mrboros
Copy link
Author

mrboros commented Mar 4, 2025

Thanks in advance! Meanwhile I have a workaround using a separate Sort parameter:
Sort sort = Sort.by("monitoring_event.monitoring_datetime"); and it works this way.

@sothawo sothawo added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 8, 2025
@sothawo sothawo self-assigned this Mar 8, 2025
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Mar 9, 2025
sothawo added a commit that referenced this issue Mar 9, 2025
Original Pull Request #3074
Closes #3072

Signed-off-by: Peter-Josef Meisch <[email protected]>
@sothawo sothawo added this to the 5.5 M2 (2025.0.0) milestone Mar 9, 2025
sothawo added a commit that referenced this issue Mar 9, 2025
Original Pull Request #3074
Closes #3072

Signed-off-by: Peter-Josef Meisch <[email protected]>
(cherry picked from commit 4238362)
sothawo added a commit that referenced this issue Mar 9, 2025
Original Pull Request #3074
Closes #3072

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

sothawo commented Mar 9, 2025

implememted in main, backported to branches 5.4.x and 5.3.x.

@mrboros
Copy link
Author

mrboros commented Mar 9, 2025

Thank you very much! Cheers

@joeha11
Copy link

joeha11 commented Mar 31, 2025

Hey, it looks like this change broke my code. Using 5.3.9, this code worked, and in 5.3.10 it does not.

        if (searchTerm.isEmpty()) { //If user didn't supply search terms, this is a pure boolean search, so sort alphabetically
            nativeQuery.addSort(Sort.by("name.keyword"));
        }

The resulting query on 5.3.9 got this (working) sort clause:

   "sort": [
       {
           "name.keyword": {
               "mode": "min",
               "order": "asc"
           }
       }
   ],

This after this change, on 5.3.10, it removes the .keyword suffix:

  "sort": [
      {
          "name": {
              "mode": "min",
              "order": "asc"
          }
      }
  ],

The consequence is that I get the following error:

# HTTP/1.1 400 Bad Request
# X-elastic-product: Elasticsearch
# content-type: application/vnd.elasticsearch+json;compatible-with=8
# content-length: 2115
#
# {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Fielddata is disabled on [name] in [myindex]. Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default.
[...]
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.data.elasticsearch.UncategorizedElasticsearchException: [es/search] failed: [search_phase_execution_exception] all shards failed] with root cause

co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [search_phase_execution_exception] all shards failed

I suspect that this was unintentional, and may be a bug? @sothawo what do you think?

@sothawo
Copy link
Collaborator

sothawo commented Mar 31, 2025

That's the same error as originally described in this issue. This is resolved and will be available with the next release of main, 5.4.x and 5.3.x.

@joeha11
Copy link

joeha11 commented Apr 2, 2025

@sothawo I'm not understanding something. I though the fix was in 5.3.10, because 5.3.10 seems to have been released March 14th and the fixing commit d7abbc7 was merged on March 9th into the 5.3.X branch? So I assumed 5.3.10 would have the fix.
My code works on 5.3.9 but not on 5.3.10.

@sothawo
Copy link
Collaborator

sothawo commented Apr 2, 2025

d7abbc7 was the change that introduced the problem with parts of the sort path. The fix for this issue was committed on March 24. see #3081

@joeha11
Copy link

joeha11 commented Apr 2, 2025

@sothawo d7abbc7 is marked as "closing" issue 3037 (this issue). Am I reading this backwards?

@joeha11
Copy link

joeha11 commented Apr 2, 2025

Oh, I see now, there is a new issue #3081 which looks similar to my problem. I think there's just a confusion of which issue we're in.

I'll just wait for the release of commit f32cbb8.
Thanks for your time, and for contributing to this great project!

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.

4 participants