MST
星途 面试题库

面试题:ElasticSearch删除API的基础使用

在ElasticSearch中,简述如何使用删除API删除单个文档。请给出具体的API调用示例,包括必要的参数和URL格式。
14.6万 热度难度
数据库ElasticSearch

知识考点

AI 面试

面试题答案

一键面试

在ElasticSearch中,使用删除API删除单个文档可以通过以下方式:

  1. URL格式DELETE /{index}/{doc_type}/{id}
    • {index} 是文档所在的索引名称。
    • {doc_type} 是文档的类型(在Elasticsearch 7.0+版本中,type已逐渐弃用,若使用的是较新版本可不填此项)。
    • {id} 是要删除文档的唯一标识符。
  2. API调用示例(以使用cURL为例)
curl -X DELETE "localhost:9200/my_index/my_type/1?pretty"
  • 上述示例中,假设ElasticSearch运行在本地 localhost:9200,要删除 my_index 索引下 my_type 类型中id为 1 的文档。?pretty 参数用于使返回结果格式化显示,便于查看。