How do I delete all data from a Solr collection? - solr

I'd like to delete all of the indexed data in my Solr collection, preferably via a shell command on one of the nodes itself. How can I do that?

If you have access to the shell, use the solrctl command with the following options:
solrctl collection --deletedocs <collection-name>
Here's the full usage output from solrctl --help for reference:
usage: /usr/bin/solrctl [options] command [command-arg] [command [command-arg]] ...
Options:
--solr solr_uri
--zk zk_ensemble
--help
--quiet
Commands:
init [--force]
instancedir [--generate path]
[--create name path]
[--update name path]
[--get name path]
[--delete name]
[--list]
collection [--create name -s <numShards>
[-c <collection.configName>]
[-r <replicationFactor>]
[-m <maxShardsPerNode>]
[-n <createNodeSet>]]
[--delete name]
[--reload name]
[--stat name]
[--deletedocs name]
[--list]
core [--create name [-p name=value]...]
[--reload name]
[--unload name]
[--status name]
If you don't have direct access, you can use Solr's update services as described here, here, and here.

you can use below command for command prompt
curl http://<ip_address>:8983/solr/<collection_name>/update --data '<delete><query>*:*</query></delete>' -H 'Content-type:text/xml; charset=utf-8';

Related

Error CREATEing SolrCore 'new_core': coreNodeName missing

I have hosted Bitnami helm chart for Apache Solr in our dev cluster and when I tried to create a new core it says ,
Error CREATEing SolrCore 'new_core': coreNodeName missing {schema=schema.xml, dataDir=data, config=solrconfig.xml}
So, from official documentation, this and this link, I came to know that I have to set legacyCloud true.
So, I have logged into my zookeeper pod, and when i ran the command
/opt/bitnami/zookeeper/bin/zkCli.sh -zkhost apachesolr-dev-zookeeper:2181 -cmd clusterprop -name legacyCloud -val true
It threw the following error,
I even tried replacing host with localhost/ 127.0.0.1 and it says command not found.
After trying for 5 hours of various approaches, I am requesting for the help as in where I am doing it wrong.
Connecting to localhost:2181
ZooKeeper -server host:port -client-configuration properties-file cmd args
addWatch [-m mode] path # optional mode is one of [PERSISTENT, PERSISTENT_RECURSIVE] - default is PERSISTENT_RECURSIVE
addauth scheme auth
close
config [-c] [-w] [-s]
connect host:port
create [-s] [-e] [-c] [-t ttl] path [data] [acl]
delete [-v version] path
deleteall path [-b batch size]
delquota [-n|-b|-N|-B] path
get [-s] [-w] path
getAcl [-s] path
getAllChildrenNumber path
getEphemerals path
history
listquota path
ls [-s] [-w] [-R] path
printwatches on|off
quit
reconfig [-s] [-v version] [[-file path] | [-members serverID=host:port1:port2;port3[,...]*]] | [-add serverId=host:port1:port2;port3[,...]]* [-remove serverId[,...]*]
redo cmdno
removewatches path [-c|-d|-a] [-l]
set [-s] [-v version] path data
setAcl [-s] [-v version] [-R] path acl
setquota -n|-b|-N|-B val path
stat [-w] path
sync path
version
whoami
Command not found: Command not found apachesolr-dev-zookeeper:2181
2022-11-03 15:42:34,114 [myid:] - ERROR [main:o.a.z.u.ServiceUtils#42] - Exiting JVM with code 127
You can do two things :
create the core from terminal/command-line.
you need to create the folder with the core name into {SOLR_PATH}/server/solr/ location and then need to add the conf files and create an empty data folder also, then it will work from solr admin.

Difference in "format" and "queryout" options available in BCP

I am trying to import data into Sybase ASE 15.7 (trial version) using BCP (version 10) on Windows.
To do so, I first try to create format file for the table with following command and get an error: Copy direction must be either 'in' or 'out'. Syntax Error in 'format'.
C:\Sybase\OCS-15_0\bin>bcp TEST_EMP2 format nul -f C:\test_files\TEST_EMP2.fmt -
c -T -t,
Copy direction must be either 'in' or 'out'.
Syntax Error in 'format'.
usage: bcp [[db_name.]owner.]table_name[:slice_num] [partition pname] {in | out}
[filename]
[-m maxerrors] [-f formatfile] [-e errfile] [-d discardfileprefix]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n] [-c] [-t field_terminator] [-r row_terminator]
[-U username] [-P password] [-I interfaces_file] [-S server]
[-a display_charset] [-z language] [-v]
[-i input_file] [-o output_file]
[-A packet size] [-J client character set]
[-T text or image size] [-E] [-g id_start_value] [-N] [-W] [-X]
[-M LabelName LabelValue] [-labeled]
[-K keytab_file] [-R remote_server_principal] [-C]
[-V [security_options]] [-Z security_mechanism] [-Q] [-Y]
[-y sybase directory] [-x trusted.txt_file]
[--clienterr errfile] [--maxconn maximum_connections]
[--show-fi] [--hide-vcc]
[--colpasswd [[[db_name.[owner].]table_name.]column_name [password]]]
[--keypasswd [[db_name.[owner].]key_name [password]]]
[--initstring ASE initialization string] [--quoted-fname]
C:\Sybase\OCS-15_0\bin>
I looked up the BCP utility options on the following site and found that option to create format file or queryout is not listed there.
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc30191.1550/html/utility/X14951.htm
bcp [[database_name.]owner.]table_name [: [ partition_id | slice_number ] |
partition partition_name] {in | out} datafile
[-f formatfile]
[-e errfile]
[-d discardfileprefix]
[-F firstrow]
[-L lastrow]
[-b batchsize]
[-m maxerrors]
[-n]
[-c]
[-t field_terminator]
[-r row_terminator]
[-U username]
[-P password]
[-I interfaces_file]
[-S server]
[-a display_charset]
[-z language]
[-A packet_size]
[-J client_charset]
[-T text_or_image_size]
[-E]
[-g id_start_value]
[-N]
[-W]
[-X]
[-M LabelName LabelValue]
[-labeled]
[-K keytab_file]
[-R remote_server_principal]
[-C]
[-V [security_options]]
[-Z security_mechanism]
[-Q]
[-Y]
[-y sybase directory]
[-x trusted.txt_file]
[--maxconn maximum_connections
[--show-fi]
[--hide-vcc]
[--colpasswd [[[database_name.[owner].table_name.]column_name
[password]]]
[--keypasswd [[database_name.[owner].]key_name [password]]]
However for SQL server, BCP description shows format and queryout options in the following description of the utility.
http://technet.microsoft.com/en-us/library/ms162802.aspx
_xCodexBlockxPlacexHolderx_Can anyone please tell me if the options to queryout and create format file using "format" option is not supported in BCP on Sybase ASE? Or is there a way to enable these?
I am aware that we can create format files manually, but that is not feasible as I have to create format files for 2000 tables.
I would like to know if anyone has faced similar issue to generate format files using BCP, and if there is a workaround to solve this issue.
Despite the same names and overlap in syntax, the utilities for Sybase ASE and MS SQL Server are quite different.
Sybase ASE bcp does not support queryout.
Also format files for Sybase BCP's are only used to define column datatypes, they are not for reordering/skipping or other actions that are available using SQL Server format files.
For Sybase ASE, format files aren't necessary to import or export data. They are only necessary if you do not specify -c (character mode) or -n (native mode) in your bcp command.

How to spilt a 4GB .sql file into smaller files

I have a 4GB sql data script of my database. I want to execute it but SQL Server Management Studio does allow me to do it because it's a very big file.
So I want to split this file into smaller files so that I can execute it. I have googled it but didn't get any good solutions. I have also used HJSplit to split the files but only first split file is in correct format but others are not in correct format due to which can not be execute in SQL query Interface.
Please help me guys how can I execute this .sql file with data with or without splitting?
use the sqlcmd tool to execute the file..
sqlcmd -S myServer\instanceName -i C:\myScript.sql
or
sqlcmd -S <server> -i C:\<your file here>.sql -o
Just replace with the location of your SQL box and with the name of your script. Don't forget if you're using a SQL instance the syntax is:
sqlcmd -S \instance.
Here is the list of all arguments you can pass sqlcmd:
Sqlcmd [-U login id] [-P password]
[-S server] [-H hostname] [-E trusted connection]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend] [-L[c] list servers[clean output]]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile] [-z new password]
[-f | i:[,o:]] [-Z new password and exit]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-b On error batch abort]
[-v var = "value"...] [-A dedicated admin connection]
[-X[1] disable commands, startup script, enviroment variables [and exit]]
[-x disable variable substitution]
[-? show syntax summary]

Send Query result into a Text file in SqlServer

I want to send the result from a scalar variable into a text file,
My Code looks like this
DECLARE #test varchar(10)
SET #test='This is sample text'
EXEC master..xp_cmdshell'bcp ' + #test + ' queryout "D:\sample.txt" -S LocalHost -U
sa -P 123 -c -T -t'
But this is showing the following errors
output
usage: bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"] [-x generate xml format file]
NULL
Dont know how to give the format assigning a scalar variable value in bcp command
Please any one help.
And tried in this way also
Create table #sample
(
productid int
)
Insert into #sample(productid) values(1001098)
EXEC master..xp_cmdshell'bcp "select * from #sample" queryout "D:\sample.txt" -S
LocalHost -U sa -P 123 -c -T -t'
It gives as Error that
#sample does not exist (in bcp command line)
Can any one please solve this.
Thanks in advance.
First thing, a temp table is bound to a scope, and thus cannot be used in a different process ID.
But, you can declare a global temp table (be sure to delete it afterward and make sure to use a very specific name to make sure you don't interfere with some other code).
To do so, you just have to double the '#' in the table name.
if object_ID('tempdb..##sample') is not null
drop table ##sample
Create table ##sample
(
productid int
)
Insert into ##sample(productid) values(1001098)
Then all you have to do is your output.
EXEC master..xp_cmdshell'bcp "select * from ##sample" queryout "d:\sample.txt" -w -U sa -P 123 -S server_name\instance_name'
As you can see I changed a couple of switches too.
I found it's preferable to use -w to generate ansi characters, so I removed -c.
-T is for trusted connection, but since you provide a username and password, you don't need it.
Then you should be fine.
Test this:
EXEC xp_cmdshell 'bcp "SELECT *FROM [YOURDATABASE].[dbo].[YOURTABLE]" queryout "f:\newOUTPUT.txt" -S DESKTOP-A5CFJSH\MSSQLSERVER1 -UYOURUSERNAME -PYOURPASSWORD -n '

Export data as fixed width file from SQL Server 2005

I thought it is a very simple task to export data in a view from SQL Server 2005 to a fixed width text file. But the wizard is a pain. The format is not correct. Does anybody know how to deal with it? or any better way to do that?
Use bcp with queryout option
http://msdn.microsoft.com/en-us/library/ms162802(SQL.90).aspx
bcp "SELECT * FROM AdventureWorks.Person.Contact" queryout Contacts.txt -c -T
Use a format file if you want fixed-width output
http://weblogs.sqlteam.com/brettk/archive/2006/07/06/10504.aspx
I just tried exporting in AdventureWorks, Fixed Width gave me a lot of issues too (compared to column delimiters)
I had to ignore the GUID columns, not include column names in the first row, etc.. finally exported Sales.Customer table
Without BCP, you may have to look into SSIS or SQLCMD
One option is to use OpenDataSource to write the rows out to a text file. This requires that the text file already exists, but is relatively easy.
This article (for disclosure, I wrote it, and it focuses on reading from, but touches on writing too) explains the basics of reading and writing from text files with OpenDataSource. : http://www.sqlservercentral.com/articles/OpenDataSource/61552/
If the format from the wizard doesn't suit your needs, you will need to develop your own SSIS package. Are you sure you really need a fixed width file? A delimited file would probably be easier to get right as they are much more common.
I have found SQL2005/SSIS to be anything but simple to do seemingly simple tasks. Things always take me 5x longer than they should. I know I'm not alone on this.
BCP should work.
Don't know about sqlcmd - seems like it doesn't do fixed width, unless you did the padding in your sql statement - which would also be a pain.
usage: Sqlcmd [-U login id] [-P password]
[-S server] [-H hostname] [-E trusted connection]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend] [-L[c] list servers[clean output]]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile] [-z new password]
[-f <codepage> | i:<codepage>[,o:<codepage>]] [-Z new password and exit]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-b On error batch abort]
[-v var = "value"...] [-A dedicated admin connection]
[-X[1] disable commands, startup script, enviroment variables [and exit]]
[-x disable variable substitution]
[-? show syntax summary]

Resources