Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\es::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/es.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\es::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/es.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\es::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
检查文档是否存在 | Elasticsearch: 权威指南 | Elastic - 互联网笔记

略微加速

Elasticsearch权威指南 - 互联网笔记

检查文档是否存在 | Elasticsearch: 权威指南 | Elastic

2025-04-19

检查文档是否存在编辑

如果只想检查一个文档是否存在 --根本不想关心内容--那么用 HEAD 方法来代替 GET 方法。 HEAD 请求没有返回体,只返回一个 HTTP 请求报头:

curl -i -XHEAD http://localhost:9200/website/blog/123

如果文档存在, Elasticsearch 将返回一个 200 ok 的状态码:

HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Content-Length: 0

若文档不存在, Elasticsearch 将返回一个 404 Not Found 的状态码:

curl -i -XHEAD http://localhost:9200/website/blog/124
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=UTF-8
Content-Length: 0

当然,一个文档仅仅是在检查的时候不存在,并不意味着一毫秒之后它也不存在:也许同时正好另一个进程就创建了该文档。

官方地址:https://www.elastic.co/guide/cn/elasticsearch/guide/current/doc-exists.html

冷却塔厂家 广告
中文GPT4.0无需注册 广告
北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3