Reputation: 1
I have documents in solr index that do not have date field. I want to remove all such documents. Following does not work, even though
date:[* TO *]
produces documents I want to keep, and
-date:[* TO *]
produces documents I want to delete.
/usr/bin/curl http:// localhost:8080/solr/update -H "Content-Type: text/xml" --data-binary '<delete><query>-date:[* TO *]</query></delete>'
/usr/bin/curl http:// localhost:8080/solr/update -H "Content-Type: text/xml" --data-binary '<commit/>'
/usr/bin/curl http:// localhost:8080/solr/update -H "Content-Type: text/xml" --data-binary '<optimize/>'
Result:
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">16</int>
</lst></response>
<?xml version="1.0" encoding="UTF-8"?><response><lst name="responseHeader"><int name="status">0</int><int name="QTime">140</int></lst></response>
<?xml version="1.0" encoding="UTF-8"?><response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">41</int></lst>
</response>
Note: Deleting date:[* TO *] documents works well.
Upvotes: 0
Views: 530
Reputation: 20356
/update?stream.body=<delete><query>*:* -(date:[* TO *])</query></delete>&commit=true
Edit: some one down-voted my answer because I didn't explain it. Here it is:
*:*
means all documentsdate:[* TO *]
means all documents which have a date field *:* -(date:[* TO *])
all documents which don't have a date fieldcommit=true
means commit the change to indexWhy <delete><query>-date:[* TO *]</query></delete>
doesn't work? Frankly speaking, I am not sure. The syntax for updating is not the same as the syntax for querying. I will post more if I figure out more in the future.
Upvotes: 1
Reputation: 32808
I had the same problem. The solution was to add an additional condition which refers to the id. So that I had in the end
<delete><query>-date:[* TO *] AND id:(*)</query></delete>
As you can see the id can have any value.
Upvotes: 1