developer tip

solr 및 hbase에서 모든 데이터를 삭제하는 방법

optionbox 2020. 9. 2. 17:40
반응형

solr 및 hbase에서 모든 데이터를 삭제하는 방법


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

다음 명령을 사용하여 삭제할 수 있습니다. 쿼리 별 삭제 명령에서 "모든 문서 일치"쿼리를 사용합니다.

'<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


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

json 데이터 게시 (예 : curl 사용)

curl -X POST -H 'Content-Type: application/json' \
    'http://<host>:<port>/solr/<core>/update?commit=true' \
    -d '{ "delete": {"query":"*:*"} }'

쿼리 별 삭제 명령에서 "모든 문서 일치"쿼리를 사용하십시오 .

또한 삭제를 실행 한 후 커밋해야하므로 인덱스를 비우려면 다음 두 명령을 실행하십시오.

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'

SolrNet을 사용하여 .Net 프레임 워크를 통해 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();

This has cleared all the documents. (I am not sure if this could be recovered, I am in learning and testing phase of Solr, so please consider backup before using this code)


fire this in the browser

http://localhost:8983/solr/update?stream.body=<delete><query>*:*</query></delete>&commit=true this commmand will delete all the documents in index in solr


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

From the command line use:

 bin/post -c core_name -type text/xml -out yes -d $'<delete><query>*:*</query></delete>'

If you need to clean out all data, it might be faster to recreate collection, e.g.

solrctl --zk localhost:2181/solr collection --delete <collectionName>
solrctl --zk localhost:2181/solr collection --create <collectionName> -s 1

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.


When clearing out a Solr index, you should also do a commit and optimize after running the delete-all query. Full steps required (curl is all you need): http://www.alphadevx.com/a/365-Clearing-a-Solr-search-index


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


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.


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.

참고URL : https://stackoverflow.com/questions/7722508/how-to-delete-all-data-from-solr-and-hbase

반응형