Exists API
exists API在文档存在时返回true,否则返回false。
Exists Request
它使用GetRequest就像使用Get API一样。它的所有可选参数都受到支持。因为exists()只返回true或false,所以我们建议关闭fetch_source和所有存储字段,这样请求会更轻一些:
GetRequest getRequest = new GetRequest(
"posts",
"doc",
"1");
getRequest.fetchSourceContext(new FetchSourceContext(false)); //Disable fetching _source.
getRequest.storedFields("_none_"); //Disable fetching stored fields.
同步请求
当以如下方式执行GetRequest时,客户端等待返回boolean值,然后继续执行代码:
boolean exists = client.exists(getRequest, RequestOptions.DEFAULT);
异步请求
client.existsAsync(getRequest, RequestOptions.DEFAULT, listener);