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

Exception on using Sort on text field keyword #3087

Closed
MagicSoup opened this issue Apr 4, 2025 · 0 comments
Closed

Exception on using Sort on text field keyword #3087

MagicSoup opened this issue Apr 4, 2025 · 0 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@MagicSoup
Copy link

MagicSoup commented Apr 4, 2025

Since version 5.4.4

Hello,
When i use the NativeQuery.builder() with a sort on a text field keyword the request fail like if the keyword was not used at all (When using the 5.4.3 there is no issue).

My Es mapping :

{
  "my-index" : {
    "mappings" : {
      "properties" : {
        "_class" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "active" : {
          "type" : "boolean"
        },
        "creation" : {
          "type" : "date"
        },
        "id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}

My pojo :

ReleaseTrainDocument {
    @Id
    @NotBlank
    private String id;
    private boolean active;
    @Field(type = FieldType.Date)
    private OffsetDateTime creation;
}

My java native query :

        NativeQuery.builder()
                .withQuery(query -> query.bool(bool -> bool.must( must -> must.term(term -> term.field("active").value(true)))))
                .withSort(Sort.by(Sort.Order.desc("id.keyword")))
                .build();   

The query is executed throught :

        try (SearchHitsIterator<T> result = elasticsearchOperations.searchForStream(query, clazz)) {
            final Set<T> documentsFound = new LinkedHashSet<>();
            while (result.hasNext()) {
                SearchHit<T> next = result.next();
                final T content = next.getContent();
                final T resultItem = converter.apply(content);
                if (resultItem != null) {
                    documentsFound.add(resultItem);
                }
            }
            return documentsFound;
        }    

When I execute the query, in the exception response body of the ES server is the same if I execute the query with a sort on a text field and not using the keyword.

Might be linked to the fix on sorting on the 5.4.4 version -> #3072

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 4, 2025
@MagicSoup MagicSoup changed the title Exception on using Sort on text feild keyword Exception on using Sort on text field keyword Apr 4, 2025
@sothawo sothawo closed this as completed Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants