简体   繁体   English

如何从Elasticsearch Index 2.2版中删除所有类型的文档

[英]How to remove all documents of type from elasticsearch index version 2.2

I'm trying to remove all documents of a specific type using the nodejs client for elastic search. 我正在尝试使用nodejs客户端进行弹性搜索来删除特定类型的所有文档。

I have this code: 我有以下代码:

var deleteType = function (type, done) {
    client().indices.delete({
      "index": settings.index,
      "type": type,
      "ignore": [404]
    }, function (error, response) {
      if (error) {
        logger.error(error, 'Failed to delete index type');
        done(error);
      } else {
        logger.debug({"res": response}, "deleted %s index", type);
        done();
      }
    });
  };

The type and index parameters are fine. 类型和索引参数很好。 But it seems to be deleting the entire index, not just docs of that type. 但是它似乎正在删除整个索引,而不仅仅是该类型的文档。 I'm guessing that I've made the wrong API call with indices.delete . 我猜想我用indices.delete进行了错误的API调用。

What is the right way to delete all documents of a specific "type" within an index? 什么是删除索引中特定“类型”的所有文档的正确方法?

Prior to version 2.0, you can delete a type in an index using the Delete Mapping as part of the Indices API . 在2.0版之前,您可以使用Delete Mapping作为Indices API的一部分删除索引中的类型。

Allow to delete a mapping (type) along with its data. 允许删除映射(类型)及其数据。 The REST endpoints are REST端点是

[DELETE] /{index}/{type} [删除] / {index} / {type}

[DELETE] /{index}/{type}/_mapping [删除] / {索引} / {类型} / _映射

[DELETE] /{index}/_mapping/{type} [删除] / {index} / _ mapping / {type}

As of version 2.0, Elasticsearch no longer supports this directly. 从2.0版开始,Elasticsearch不再直接支持此功能。 The documentation explains it like this: 文档解释如下:

It is no longer possible to delete the mapping for a type. 不再可能删除类型的映射。 Instead you should delete the index and recreate it with the new mappings. 相反,您应该删除索引并使用新的映射重新创建它。

However, this functionality is made available by the Delete By Query Plugin . 但是,“ 按查询删除”插件可提供此功能。

The delete-by-query plugin adds support for deleting all of the documents (from one or more indices) which match the specified query. “按查询删除”插件增加了对删除与指定查询匹配的所有文档(从一个或多个索引)的支持。 It is a replacement for the problematic delete-by-query functionality which has been removed from Elasticsearch core. 它替代了有问题的按查询删除功能,该功能已从Elasticsearch核心中删除。

Simply construct a query that filters for the type in your index you want to delete, and use that as the basis for your "Delete By Query". 只需构造一个查询,该查询将过滤要删除的索引中的类型,并将其用作“按查询删除”的基础。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何删除elasticsearch中一个索引的所有文档中的一个元素? - How remove an element in all documents of an index in elasticsearch? 如何从Elasticsearch索引中删除所有文档 - How to delete all documents from an elasticsearch index 如何在elasticsearch中根据索引和类型获取所有文档的字数? - How to get the word count for all the documents based on index and type in elasticsearch? ElasticSearch和NEST:如何从索引中清除所有文档? - ElasticSearch and NEST: How do you purge all documents from an index? 如何使用 RestHighLevelClient 从弹性搜索中的索引中删除所有文档 - How to delete all documents from index in an elasticsearch using RestHighLevelClient Elasticsearch:使用python从索引中检索所有文档 - Elasticsearch : retrieve all documents from index with python 从索引获取所有文档-elasticsearch - Get all documents from an index - elasticsearch Elastica或ElasticSearch从所有文档中删除字段 - Elastica or ElasticSearch remove field from all documents 根据字段定期从 Elasticsearch 索引中删除文档 - Periodically remove documents from Elasticsearch index depending on field 如何从 Elasticsearch 的过滤器中获取所有文档? - How to get all documents from a filter in Elasticsearch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM