ema
ema

Reputation: 1

Negative selection cannot be deleted from solr index

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

Answers (2)

Tyler Liu
Tyler Liu

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:

  1. *:* means all documents
  2. date:[* TO *] means all documents which have a date field
  3. *:* -(date:[* TO *]) all documents which don't have a date field
  4. commit=true means commit the change to index

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

H6_
H6_

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

Related Questions