Solr
  1. Solr
  2. SOLR-6357

Using query time Join in deleteByQuery throws ClassCastException

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.9
    • Fix Version/s: 5.3, 6.0
    • Component/s: query parsers
    • Labels:
      None

      Description

      Consider the following input document where we have:

      • 1 Samsung mobile phone and
      • 2 manufactures: Apple and Samsung.
      [
         {
            "id":"galaxy note ii",
            "cat":"product",
            "manu_s":"samsung"
         },
         {
            "id":"samsung",
            "cat":"manufacturer",
            "name":"Samsung Electronics"
         },
         {
            "id":"apple",
            "cat":"manufacturer",
            "name":"Apple Inc"
         }
      ]
      

      My objective is to delete from the default index all manufacturers not having any product in the index.

      After indexing ( curl 'http://localhost:8983/solr/update?commit=true' -H "Content-Type: text/json" --data-binary @delete-by-join-query.json )

      I went to

      http://localhost:8983/solr/select?q=cat:manufacturer -{!join from=manu_s to=id}cat:product
      

      and I could see only Apple, the only manufacturer not having any product in the index.

      However, when I use that same query for deletion:

      http://localhost:8983/solr/update?commit=true&stream.body=<delete><query>cat:manufacturer -{!join from=manu_s to=id}cat:product</query></delete>
      

      I get

      java.lang.ClassCastException: org.apache.lucene.search.IndexSearcher cannot be cast to org.apache.solr.search.SolrIndexSearcher
      	at org.apache.solr.search.JoinQuery.createWeight(JoinQParserPlugin.java:143)
      	at org.apache.lucene.search.BooleanQuery$BooleanWeight.<init>(BooleanQuery.java:185)
      	at org.apache.lucene.search.BooleanQuery.createWeight(BooleanQuery.java:526)
      	at org.apache.lucene.search.BooleanQuery$BooleanWeight.<init>(BooleanQuery.java:185)
      	at org.apache.lucene.search.BooleanQuery.createWeight(BooleanQuery.java:526)
      	at org.apache.lucene.search.IndexSearcher.createNormalizedWeight(IndexSearcher.java:684)
      	at org.apache.lucene.search.QueryWrapperFilter.getDocIdSet(QueryWrapperFilter.java:55)
      	at org.apache.lucene.index.BufferedUpdatesStream.applyQueryDeletes(BufferedUpdatesStream.java:552)
      	at org.apache.lucene.index.BufferedUpdatesStream.applyDeletesAndUpdates(BufferedUpdatesStream.java:287)
      	at 
      

      This seems to be a bug.

      Looking at the source code, the exception is happening in

       @Override
        public Weight createWeight(IndexSearcher searcher) throws IOException {
          return new JoinQueryWeight((SolrIndexSearcher)searcher);
        }
      
      1. SOLR-6357.patch
        0.9 kB
        Timothy Potter

        Issue Links

          Activity

          Hide
          Mikhail Khludnev added a comment -

          I'm not sure but it might be challenging to use purely Solr query {!join ..} deep inside of Lucene core, where deleteQuery is handled. Try to use native Lucene query-time join SOLR-6234.

          Show
          Mikhail Khludnev added a comment - I'm not sure but it might be challenging to use purely Solr query {!join ..} deep inside of Lucene core, where deleteQuery is handled. Try to use native Lucene query-time join SOLR-6234 .
          Hide
          Mikhail Khludnev added a comment -

          SOLR-6234 is a solution

          Show
          Mikhail Khludnev added a comment - SOLR-6234 is a solution
          Hide
          Timothy Potter added a comment -

          Adding a unit test that uses the score join solution to fix this issue.

          Show
          Timothy Potter added a comment - Adding a unit test that uses the score join solution to fix this issue.
          Hide
          Timothy Potter added a comment -

          Here's a patch with a simple unit test to verify that delete by query works using score join.

          Show
          Timothy Potter added a comment - Here's a patch with a simple unit test to verify that delete by query works using score join.
          Hide
          Mikhail Khludnev added a comment -

          +1 for commit.

          Show
          Mikhail Khludnev added a comment - +1 for commit.
          Hide
          ASF subversion and git services added a comment -

          Commit 1693338 from Timothy Potter in branch 'dev/trunk'
          [ https://svn.apache.org/r1693338 ]

          SOLR-6357: Allow delete documents by doing a score join query.

          Show
          ASF subversion and git services added a comment - Commit 1693338 from Timothy Potter in branch 'dev/trunk' [ https://svn.apache.org/r1693338 ] SOLR-6357 : Allow delete documents by doing a score join query.
          Hide
          ASF subversion and git services added a comment -

          Commit 1693339 from Timothy Potter in branch 'dev/branches/branch_5x'
          [ https://svn.apache.org/r1693339 ]

          SOLR-6357: Allow delete documents by doing a score join query.

          Show
          ASF subversion and git services added a comment - Commit 1693339 from Timothy Potter in branch 'dev/branches/branch_5x' [ https://svn.apache.org/r1693339 ] SOLR-6357 : Allow delete documents by doing a score join query.
          Hide
          Timothy Potter added a comment -

          Thanks Mikhail Khludnev! Nice work on the score join stuff.

          Show
          Timothy Potter added a comment - Thanks Mikhail Khludnev ! Nice work on the score join stuff.
          Hide
          Arcadius Ahouansou added a comment -

          Thanks Timothy Potter for fixing this issue.

          Show
          Arcadius Ahouansou added a comment - Thanks Timothy Potter for fixing this issue.
          Hide
          Shalin Shekhar Mangar added a comment -

          Bulk close for 5.3.0 release

          Show
          Shalin Shekhar Mangar added a comment - Bulk close for 5.3.0 release

            People

            • Assignee:
              Timothy Potter
              Reporter:
              Arcadius Ahouansou
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development