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

Consider use "exists" replace "get" to check document exists #2726

Closed
mawen12 opened this issue Oct 12, 2023 · 0 comments
Closed

Consider use "exists" replace "get" to check document exists #2726

mawen12 opened this issue Oct 12, 2023 · 0 comments
Labels
type: enhancement A general enhancement

Comments

@mawen12
Copy link
Contributor

mawen12 commented Oct 12, 2023

Elasticsearch Official Documentation say can use HEAD to check document exists.

In Spring Data Elasticsearch Project, ElasticsearchTemplate#doExists(String, IndexCoordinates) use GetRequest, maybe can use ExistsRequest to replace it。

current code:

@Override
protected boolean doExists(String id, IndexCoordinates index) {

  Assert.notNull(id, "id must not be null");
  Assert.notNull(index, "index must not be null");

  GetRequest request = requestConverter.documentGetRequest(id, routingResolver.getRouting(), index, true);

  return execute(client -> client.get(request, EntityAsMap.class)).found();
}

after:

@Override
protected boolean doExists(String id, IndexCoordinates index) {

  Assert.notNull(id, "id must not be null");
  Assert.notNull(index, "index must not be null");

  // the method is not exists, need to add
  ExistsRequest request = requestConverter.documentExistsRequest(id, routingResolver.getRouting(), index);

  return execute(client -> client.exists(request)).value();
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 12, 2023
@sothawo sothawo added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 12, 2023
mawen12 added a commit to mawen12/spring-data-elasticsearch that referenced this issue Oct 12, 2023
Use ExistsRequest replace GetRequest to check documents exists.
mawen12 added a commit to mawen12/spring-data-elasticsearch that referenced this issue Oct 13, 2023
…ects#2726

# Conflicts:
#	src/main/java/org/springframework/data/elasticsearch/client/elc/ReactiveElasticsearchTemplate.java
@sothawo sothawo added this to the 5.2 GA (2023.1.0) milestone Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants