Skip to content

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

Closed
@mawen12

Description

@mawen12

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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions