How to delete all data from solr and hbase

2019-03-07 13:11发布

How do I delete all data from solr by command? We are using solr with lily and hbase.

How can I delete data from both hbase and solr?

http://lucene.apache.org/solr/4_10_0/tutorial.html#Deleting+Data

标签: solr hbase
16条回答
啃猪蹄的小仙女
2楼-- · 2019-03-07 13:13

Solr I am not sure but you can delete all the data from hbase using truncate command like below:

truncate 'table_name'

It will delete all row-keys from hbase table.

查看更多
走好不送
3楼-- · 2019-03-07 13:14

If you want to delete all of the data in Solr via SolrJ do something like this.

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);
    }
}

If you want to delete all of the data in HBase do something like this.

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);
    }
 }
查看更多
甜甜的少女心
4楼-- · 2019-03-07 13:15

I made a JavaScript bookmark which adds the delete link in 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>');
})();

enter image description here

查看更多
倾城 Initia
5楼-- · 2019-03-07 13:18

The curl examples above all failed for me when I ran them from a cygwin terminal. There were errors like this when i ran the script example.

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>

I needed to use the delete in a loop on core names to wipe them all out in a project.

This query below worked for me in the Cygwin terminal script.

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>

This one line made the data go away and the change persisted.

查看更多
我命由我不由天
6楼-- · 2019-03-07 13:19

I've used this query to delete all my records.

http://host/solr/core-name/update?stream.body=%3Cdelete%3E%3Cquery%3E*:*%3C/query%3E%3C/delete%3E&commit=true
查看更多
一夜七次
7楼-- · 2019-03-07 13:20

If you're using Cloudera 5.x, Here in this documentation is mentioned that Lily maintains the Real time updations and deletions also.

Configuring the Lily HBase NRT Indexer Service for Use with Cloudera Search

As HBase applies inserts, updates, and deletes to HBase table cells, the indexer keeps Solr consistent with the HBase table contents, using standard HBase replication.

Not sure iftruncate 'hTable' is also supported in the same.

Else you create a Trigger or Service to clear up your data from both Solr and HBase on a particular Event or anything.

查看更多
登录 后发表回答