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

Please use "exists" replace "get" to check document exists #2149

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

Please use "exists" replace "get" to check document exists #2149

mawen12 opened this issue Oct 12, 2023 · 0 comments

Comments

@mawen12
Copy link

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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants