Question

How do I pick/ delete all the documents from Solr using the boolean NOT notion?

i.e. How do I delete all the documents from Solr who's id does NOT start with A59?

Was it helpful?

Solution

Use - to indicate NOT.

For example, to query documents with id not starting with A59, the query would be: -id:A59*, that is: /solr/select/?q=-id:A59*

To delete by query, post the query in a delete message to the update handler, as specified here.

EDIT: NOT (all uppercase) can also be used as boolean operator

OTHER TIPS

Exclamation works for NOT as well, so:

/solr/select/?q=!id:A59*

should work in the case above.

I don't believe that a negative delete by query works. See this Jira ticket: https://issues.apache.org/jira/browse/SOLR-381

They do say that there is a workaround to prefix in a :, but I do not have any luck with that.

This does not work (same with using NOT) java -Ddata=args -jar /opt/solr/example/exampledocs/post.jar "-userid:*" java -jar /opt/solr/example/exampledocs/post.jar *.xml

Adding in a : gives a syntax error (same with using NOT) java -Ddata=args -jar /opt/solr/example/exampledocs/post.jar ": -userid:*" java -jar /opt/solr/example/exampledocs/post.jar *.xml

SimplePostTool: version 1.4 SimplePostTool: POSTing args to http://localhost:8983/solr/update.. SimplePostTool: FATAL: Solr returned an error #400 Error parsing Lucene query SimplePostTool: version 1.4

before deleting please ensure that the ids that you are referring to is string and in no way would be formed by two terms combined . The way I would do it is read the data from solr from a script and do a singular delete or in batches , because it provides a better control and validations over each ids which reduces the risk of wrong deletion Hence 1 read the data from solr from a script using /solr/select/?q=id:A59*

2 verify and validate the ids

3 delete them one by one or in a group of 10 ids at once

Regards

Rajat

As Mauricio stated:

Use the - symbol to indicate what you want exclude in your query. The following two queries will delete all documents except the ones that begin with A59.

GET http://<url>/solr/<core>/update?stream.body=<delete><query>-id:A59*</query></delete>
GET http://<url>/solr/<core>/update?stream.body=<commit/>

The first line does the delete operation. The second line does the commit.

Using the - symbol in-front of the files to implies that exclude that particular value. It will give result like NOT Equal

The following is sample url query string where. I have kept "&fq=-HQ_City_Code:MEL",

It will skip all the result which is having HQ_City_Code value MEL.

http://localhost:8983/solr/HQ_SOLR_Hotels/select?q=*:*&fq=HQ_National_Code:TH&fq=HQ_TYPE:hotel_EN&fq=HQ_Country_Code:AU&**fq=-HQ_City_Code:MEL**&wt=json&indent=true
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top