【发布时间】:2011-12-05 01:39:59
【问题描述】:
如何通过命令删除solr 中的所有数据?我们将solr 与lily 和hbase 一起使用。
如何从 hbase 和 solr 中删除数据?
http://lucene.apache.org/solr/4_10_0/tutorial.html#Deleting+Data
【问题讨论】:
如何通过命令删除solr 中的所有数据?我们将solr 与lily 和hbase 一起使用。
如何从 hbase 和 solr 中删除数据?
http://lucene.apache.org/solr/4_10_0/tutorial.html#Deleting+Data
【问题讨论】:
如果要清理 Solr 索引 -
你可以触发 http url -
http://host:port/solr/[core name]/update?stream.body=<delete><query>*:*</query></delete>&commit=true
(将[core name] 替换为您要从中删除的核心的名称)。或者在发布数据 xml 数据时使用它:
<delete><query>*:*</query></delete>
确保使用commit=true 提交更改
虽然对清除 hbase 数据不太了解。
【讨论】:
&commit=true 添加到查询中,使其变为http://host:port/solr/core/update?stream.body=<delete><query>*:*</query></delete>&commit=true 没有它我想知道为什么没有删除所有文档。
我已使用此请求删除我的所有记录,但有时需要提交此请求。
为此,请将&commit=true 添加到您的请求中:
http://host:port/solr/core/update?stream.body=<delete><query>*:*</query></delete>&commit=true
【讨论】:
如果您想通过 SolrJ 删除 Solr 中的所有数据,请执行以下操作。
public static void deleteAllSolrData() {
HttpSolrServer solr = new HttpSolrServer("http://localhost:8080/solr/core/");
try {
solr.deleteByQuery("*:*");
} catch (SolrServerException e) {
throw new RuntimeException("Failed to delete data in Solr. "
+ e.getMessage(), e);
} catch (IOException e) {
throw new RuntimeException("Failed to delete data in Solr. "
+ e.getMessage(), e);
}
}
如果要删除 HBase 中的所有数据,请执行以下操作。
public static void deleteHBaseTable(String tableName, Configuration conf) {
HBaseAdmin admin = null;
try {
admin = new HBaseAdmin(conf);
admin.disableTable(tableName);
admin.deleteTable(tableName);
} catch (MasterNotRunningException e) {
throw new RuntimeException("Unable to delete the table " + tableName
+ ". The actual exception is: " + e.getMessage(), e);
} catch (ZooKeeperConnectionException e) {
throw new RuntimeException("Unable to delete the table " + tableName
+ ". The actual exception is: " + e.getMessage(), e);
} catch (IOException e) {
throw new RuntimeException("Unable to delete the table " + tableName
+ ". The actual exception is: " + e.getMessage(), e);
} finally {
close(admin);
}
}
【讨论】:
在清除 Solr 索引时,您还应该在运行 delete-all 查询后进行提交和优化。需要完整的步骤(你只需要 curl):http://www.alphadevx.com/a/365-Clearing-a-Solr-search-index
【讨论】:
我来这里是为了通过 .Net 框架使用 SolrNet 从 solr 实例中删除所有文档。这是我能够做到的:
Startup.Init<MyEntity>("http://localhost:8081/solr");
ISolrOperations<MyEntity> solr =
ServiceLocator.Current.GetInstance<ISolrOperations<MyEntity>>();
SolrQuery sq = new SolrQuery("*:*");
solr.Delete(sq);
solr.Commit();
这已经清除了所有文件。 (我不确定这是否可以恢复,我在 Solr 的学习和测试阶段,所以在使用此代码之前请考虑备份)
【讨论】:
在浏览器中触发
http://localhost:8983/solr/update?stream.body=<delete><query>*:*</query></delete>&commit=true
此命令将删除 solr 中 index 中的所有文档
【讨论】:
如果您需要清除所有数据,重新创建集合可能会更快,例如
solrctl --zk localhost:2181/solr collection --delete <collectionName>
solrctl --zk localhost:2181/solr collection --create <collectionName> -s 1
【讨论】:
在删除查询命令中使用“匹配所有文档”查询::
您还必须在运行删除后提交,因此,要清空索引,请运行以下两个命令:
curl http://localhost:8983/solr/update --data '<delete><query>*:*</query></delete>' -H 'Content-type:text/xml; charset=utf-8'
curl http://localhost:8983/solr/update --data '<commit/>' -H 'Content-type:text/xml; charset=utf-8'
【讨论】:
<core> 配合得很好。我编辑了答案。
我制作了一个 JavaScript 书签,在 Solr Admin UI 中添加了删除链接
javascript: (function() {
var str, $a, new_href, href, upd_str = 'update?stream.body=<delete><query>*:*</query></delete>&commit=true';
$a = $('#result a#url');
href = $a.attr('href');
str = href.match('.+solr\/.+\/(.*)')[1];
new_href = href.replace(str, upd_str);
$('#result').prepend('<a id="url_upd" class="address-bar" href="' + new_href + '"><strong>DELETE ALL</strong> ' + new_href + '</a>');
})();
【讨论】:
您可以使用以下命令进行删除。
在删除查询命令中使用“匹配所有文档”查询:
'<delete><query>*:*</query></delete>
您还必须在运行删除后提交,因此,要清空索引,请运行以下两个命令:
curl http://localhost:8983/solr/update --data '<delete><query>*:*</query></delete>' -H 'Content-type:text/xml; charset=utf-8'
curl http://localhost:8983/solr/update --data '<commit/>' -H 'Content-type:text/xml; charset=utf-8'
另一种策略是在浏览器中添加两个书签:
http://localhost:8983/solr/update?stream.body=<delete><query>*:*</query></delete>
http://localhost:8983/solr/update?stream.body=<commit/>
来自 SOLR 的源文档:
https://wiki.apache.org/solr/FAQ#How_can_I_delete_all_documents_from_my_index.3F
【讨论】:
我已使用此查询删除了我的所有记录。
http://host/solr/core-name/update?stream.body=%3Cdelete%3E%3Cquery%3E*:*%3C/query%3E%3C/delete%3E&commit=true
【讨论】:
当我从 cygwin 终端运行它们时,上面的 curl 示例对我来说都失败了。当我运行脚本示例时出现这样的错误。
curl http://192.168.2.20:7773/solr/CORE1/update --data '<delete><query>*:*</query></delete>' -H 'Content-type:text/xml; charset=utf-8'
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">1</int></lst>
</response>
<!--
It looks like it deleted stuff, but it did not go away
maybe because the committing call failed like so
-->
curl http://192.168.1.2:7773/solr/CORE1/update --data-binary '' -H 'Content-type:text/xml; charset=utf-8'
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">400</int><int name="QTime">2</int></lst><lst name="error"><str name="msg">Unexpected EOF in prolog
at [row,col {unknown-source}]: [1,0]</str><int name="code">400</int></lst>
</response>
我需要在核心名称的循环中使用 delete 以在项目中将它们全部清除。
下面的这个查询在 Cygwin 终端脚本中对我有用。
curl http://192.168.1.2:7773/hpi/CORE1/update?stream.body=<delete><query>*:*</query></delete>&commit=true
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">1</int></lst>
</response>
这一行使数据消失了,更改仍然存在。
【讨论】:
如果您使用的是 Cloudera 5.x,在此文档中提到 Lily 还维护实时更新和删除。
Configuring the Lily HBase NRT Indexer Service for Use with Cloudera Search
当 HBase 对 HBase 表格单元应用插入、更新和删除时, 索引器使 Solr 与 HBase 表内容保持一致,使用 标准 HBase 复制。
不确定是否同样支持truncate 'hTable'。
否则,您可以创建触发器或服务来清除 Solr 和 HBase 中有关特定事件或任何内容的数据。
【讨论】:
发布 json 数据(例如使用 curl)
curl -X POST -H 'Content-Type: application/json' \
'http://<host>:<port>/solr/<core>/update?commit=true' \
-d '{ "delete": {"query":"*:*"} }'
【讨论】:
Solr 我不确定,但您可以使用 truncate 命令从 hbase 中删除所有数据,如下所示:
truncate 'table_name'
它将从 hbase 表中删除所有行键。
【讨论】:
从命令行使用:
bin/post -c core_name -type text/xml -out yes -d $'<delete><query>*:*</query></delete>'
【讨论】:
我尝试了以下步骤。效果很好。
只需单击链接Delete all SOLR data,它将点击并删除所有 SOLR 索引数据,然后您将在屏幕上获得以下详细信息作为输出。
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">494</int>
</lst>
</response>
如果您没有得到上述输出,请确认以下内容。
host (localhost) 和port (8080)。如果您的主机和端口不同,请更改主机和端口。 collection / collection1。我在上面的链接中使用了collection1。如果您的核心名称不同,请也更改它。【讨论】:
要删除 Solr 集合的所有文档,您可以使用此请求:
curl -X POST -H 'Content-Type: application/json' --data-binary '{"delete":{"query":"*:*" }}' http://localhost:8983/solr/my_collection/update?commit=true
它使用 JSON 正文。
【讨论】:
/update?commit=true 可能会更好。 JSON 请求正文本身效果很好:)