Class SolrClient

    • Constructor Detail

      • SolrClient

        public SolrClient()
    • Method Detail

      • add

        public UpdateResponse add​(String collection,
                                  SolrInputDocument doc,
                                  int commitWithinMs)
                           throws SolrServerException,
                                  IOException
        Adds a single document specifying max time before it becomes committed
        Parameters:
        collection - the Solr collection to add the document to
        doc - the input document
        commitWithinMs - max time (in ms) before a commit will happen
        Returns:
        an UpdateResponse from the server
        Throws:
        IOException - if there is a communication error with the server
        SolrServerException - if there is an error on the server
        Since:
        solr 5.1
      • commit

        public UpdateResponse commit​(String collection)
                              throws SolrServerException,
                                     IOException
        Performs an explicit commit, causing pending documents to be committed for indexing waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access

        Be very careful when triggering commits from the client side. Commits are heavy operations and WILL impact Solr performance when executed too often or too close together. Instead, consider using 'commitWithin' when adding documents or rely on your core's/collection's 'autoCommit' settings.

        Parameters:
        collection - the Solr collection to send the commit to
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • commit

        public UpdateResponse commit()
                              throws SolrServerException,
                                     IOException
        Performs an explicit commit, causing pending documents to be committed for indexing waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access

        Be very careful when triggering commits from the client side. Commits are heavy operations and WILL impact Solr performance when executed too often or too close together. Instead, consider using 'commitWithin' when adding documents or rely on your core's/collection's 'autoCommit' settings.

        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • commit

        public UpdateResponse commit​(String collection,
                                     boolean waitFlush,
                                     boolean waitSearcher)
                              throws SolrServerException,
                                     IOException
        Performs an explicit commit, causing pending documents to be committed for indexing Be very careful when triggering commits from the client side. Commits are heavy operations and WILL impact Solr performance when executed too often or too close together. Instead, consider using 'commitWithin' when adding documents or rely on your core's/collection's 'autoCommit' settings.
        Parameters:
        collection - the Solr collection to send the commit to
        waitFlush - block until index changes are flushed to disk
        waitSearcher - block until a new searcher is opened and registered as the main query searcher, making the changes visible
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • commit

        public UpdateResponse commit​(boolean waitFlush,
                                     boolean waitSearcher)
                              throws SolrServerException,
                                     IOException
        Performs an explicit commit, causing pending documents to be committed for indexing Be very careful when triggering commits from the client side. Commits are heavy operations and WILL impact Solr performance when executed too often or too close together. Instead, consider using 'commitWithin' when adding documents or rely on your core's/collection's 'autoCommit' settings.
        Parameters:
        waitFlush - block until index changes are flushed to disk
        waitSearcher - block until a new searcher is opened and registered as the main query searcher, making the changes visible
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • commit

        public UpdateResponse commit​(String collection,
                                     boolean waitFlush,
                                     boolean waitSearcher,
                                     boolean softCommit)
                              throws SolrServerException,
                                     IOException
        Performs an explicit commit, causing pending documents to be committed for indexing Be very careful when triggering commits from the client side. Commits are heavy operations and WILL impact Solr performance when executed too often or too close together. Instead, consider using 'commitWithin' when adding documents or rely on your core's/collection's 'autoCommit' settings.
        Parameters:
        collection - the Solr collection to send the commit to
        waitFlush - block until index changes are flushed to disk
        waitSearcher - block until a new searcher is opened and registered as the main query searcher, making the changes visible
        softCommit - makes index changes visible while neither fsync-ing index files nor writing a new index descriptor
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • commit

        public UpdateResponse commit​(boolean waitFlush,
                                     boolean waitSearcher,
                                     boolean softCommit)
                              throws SolrServerException,
                                     IOException
        Performs an explicit commit, causing pending documents to be committed for indexing Be very careful when triggering commits from the client side. Commits are heavy operations and WILL impact Solr performance when executed too often or too close together. Instead, consider using 'commitWithin' when adding documents or rely on your core's/collection's 'autoCommit' settings.
        Parameters:
        waitFlush - block until index changes are flushed to disk
        waitSearcher - block until a new searcher is opened and registered as the main query searcher, making the changes visible
        softCommit - makes index changes visible while neither fsync-ing index files nor writing a new index descriptor
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • optimize

        public UpdateResponse optimize​(String collection)
                                throws SolrServerException,
                                       IOException
        Performs an explicit optimize, causing a merge of all segments to one. waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access Note: In most cases it is not required to do explicit optimize
        Parameters:
        collection - the Solr collection to send the optimize to
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • optimize

        public UpdateResponse optimize()
                                throws SolrServerException,
                                       IOException
        Performs an explicit optimize, causing a merge of all segments to one. waitFlush=true and waitSearcher=true to be inline with the defaults for plain HTTP access Note: In most cases it is not required to do explicit optimize
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • optimize

        public UpdateResponse optimize​(String collection,
                                       boolean waitFlush,
                                       boolean waitSearcher)
                                throws SolrServerException,
                                       IOException
        Performs an explicit optimize, causing a merge of all segments to one.

        Note: In most cases it is not required to do explicit optimize

        Parameters:
        collection - the Solr collection to send the optimize to
        waitFlush - block until index changes are flushed to disk
        waitSearcher - block until a new searcher is opened and registered as the main query searcher, making the changes visible
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • optimize

        public UpdateResponse optimize​(boolean waitFlush,
                                       boolean waitSearcher)
                                throws SolrServerException,
                                       IOException
        Performs an explicit optimize, causing a merge of all segments to one.

        Note: In most cases it is not required to do explicit optimize

        Parameters:
        waitFlush - block until index changes are flushed to disk
        waitSearcher - block until a new searcher is opened and registered as the main query searcher, making the changes visible
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • optimize

        public UpdateResponse optimize​(String collection,
                                       boolean waitFlush,
                                       boolean waitSearcher,
                                       int maxSegments)
                                throws SolrServerException,
                                       IOException
        Performs an explicit optimize, causing a merge of all segments to one. Note: In most cases it is not required to do explicit optimize
        Parameters:
        collection - the Solr collection to send the optimize to
        waitFlush - block until index changes are flushed to disk
        waitSearcher - block until a new searcher is opened and registered as the main query searcher, making the changes visible
        maxSegments - optimizes down to at most this number of segments
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • optimize

        public UpdateResponse optimize​(boolean waitFlush,
                                       boolean waitSearcher,
                                       int maxSegments)
                                throws SolrServerException,
                                       IOException
        Performs an explicit optimize, causing a merge of all segments to one. Note: In most cases it is not required to do explicit optimize
        Parameters:
        waitFlush - block until index changes are flushed to disk
        waitSearcher - block until a new searcher is opened and registered as the main query searcher, making the changes visible
        maxSegments - optimizes down to at most this number of segments
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • rollback

        public UpdateResponse rollback​(String collection)
                                throws SolrServerException,
                                       IOException
        Performs a rollback of all non-committed documents pending. Note that this is not a true rollback as in databases. Content you have previously added may have been committed due to autoCommit, buffer full, other client performing a commit etc.

        Also note that rollbacks reset changes made by all clients. Use this method carefully when multiple clients, or multithreaded clients are in use.

        Parameters:
        collection - the Solr collection to send the rollback to
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • rollback

        public UpdateResponse rollback()
                                throws SolrServerException,
                                       IOException
        Performs a rollback of all non-committed documents pending. Note that this is not a true rollback as in databases. Content you have previously added may have been committed due to autoCommit, buffer full, other client performing a commit etc.

        Also note that rollbacks reset changes made by all clients. Use this method carefully when multiple clients, or multithreaded clients are in use.

        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • deleteById

        public UpdateResponse deleteById​(String collection,
                                         String id,
                                         int commitWithinMs)
                                  throws SolrServerException,
                                         IOException
        Deletes a single document by unique ID, specifying max time before commit. Doesn't work for child/nested docs.
        Parameters:
        collection - the Solr collection to delete the document from
        id - the ID of the document to delete
        commitWithinMs - max time (in ms) before a commit will happen
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
        Since:
        5.1
      • deleteById

        public UpdateResponse deleteById​(String id,
                                         int commitWithinMs)
                                  throws SolrServerException,
                                         IOException
        Deletes a single document by unique ID, specifying max time before commit. Doesn't work for child/nested docs.
        Parameters:
        id - the ID of the document to delete
        commitWithinMs - max time (in ms) before a commit will happen
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
        Since:
        3.6
      • deleteById

        public UpdateResponse deleteById​(String collection,
                                         List<String> ids)
                                  throws SolrServerException,
                                         IOException
        Deletes a list of documents by unique ID. Doesn't work for child/nested docs.
        Parameters:
        collection - the Solr collection to delete the documents from
        ids - the list of document IDs to delete; must be non-null and contain elements
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • deleteById

        public UpdateResponse deleteById​(String collection,
                                         List<String> ids,
                                         int commitWithinMs)
                                  throws SolrServerException,
                                         IOException
        Deletes a list of documents by unique ID, specifying max time before commit. Doesn't work for child/nested docs.
        Parameters:
        collection - the Solr collection to delete the documents from
        ids - the list of document IDs to delete; must be non-null and contain elements
        commitWithinMs - max time (in ms) before a commit will happen
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
        Since:
        5.1
      • deleteById

        public UpdateResponse deleteById​(List<String> ids,
                                         int commitWithinMs)
                                  throws SolrServerException,
                                         IOException
        Deletes a list of documents by unique ID, specifying max time before commit. Doesn't work for child/nested docs.
        Parameters:
        ids - the list of document IDs to delete
        commitWithinMs - max time (in ms) before a commit will happen
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
        Since:
        3.6
      • deleteByQuery

        public UpdateResponse deleteByQuery​(String collection,
                                            String query,
                                            int commitWithinMs)
                                     throws SolrServerException,
                                            IOException
        Deletes documents from the index based on a query, specifying max time before commit
        Parameters:
        collection - the Solr collection to delete the documents from
        query - the query expressing what documents to delete
        commitWithinMs - max time (in ms) before a commit will happen
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
        Since:
        5.1
      • deleteByQuery

        public UpdateResponse deleteByQuery​(String query,
                                            int commitWithinMs)
                                     throws SolrServerException,
                                            IOException
        Deletes documents from the index based on a query, specifying max time before commit
        Parameters:
        query - the query expressing what documents to delete
        commitWithinMs - max time (in ms) before a commit will happen
        Returns:
        an UpdateResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
        Since:
        3.6
      • queryAndStreamResponse

        public QueryResponse queryAndStreamResponse​(String collection,
                                                    SolrParams params,
                                                    StreamingResponseCallback callback)
                                             throws SolrServerException,
                                                    IOException
        Query solr, and stream the results. Unlike the standard query, this will send events for each Document rather then add them to the QueryResponse. Although this function returns a 'QueryResponse' it should be used with care since it excludes anything that was passed to callback. Also note that future version may pass even more info to the callback and may not return the results in the QueryResponse.
        Parameters:
        collection - the Solr collection to query
        params - an object holding all key/value parameters to send along the request
        callback - the callback to stream results to
        Returns:
        a QueryResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
        Since:
        solr 5.1
      • queryAndStreamResponse

        public QueryResponse queryAndStreamResponse​(SolrParams params,
                                                    StreamingResponseCallback callback)
                                             throws SolrServerException,
                                                    IOException
        Query solr, and stream the results. Unlike the standard query, this will send events for each Document rather then add them to the QueryResponse. Although this function returns a 'QueryResponse' it should be used with care since it excludes anything that was passed to callback. Also note that future version may pass even more info to the callback and may not return the results in the QueryResponse.
        Parameters:
        params - an object holding all key/value parameters to send along the request
        callback - the callback to stream results to
        Returns:
        a QueryResponse containing the response from the server
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
        Since:
        solr 4.0
      • getById

        public SolrDocument getById​(String collection,
                                    String id)
                             throws SolrServerException,
                                    IOException
        Retrieves the SolrDocument associated with the given identifier.
        Parameters:
        collection - the Solr collection to query
        id - the id
        Returns:
        retrieved SolrDocument, or null if no document is found.
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • getById

        public SolrDocument getById​(String collection,
                                    String id,
                                    SolrParams params)
                             throws SolrServerException,
                                    IOException
        Retrieves the SolrDocument associated with the given identifier and uses the SolrParams to execute the request.
        Parameters:
        collection - the Solr collection to query
        id - the id
        params - additional parameters to add to the query
        Returns:
        retrieved SolrDocument, or null if no document is found.
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • getById

        public SolrDocument getById​(String id,
                                    SolrParams params)
                             throws SolrServerException,
                                    IOException
        Retrieves the SolrDocument associated with the given identifier and uses the SolrParams to execute the request.
        Parameters:
        id - the id
        params - additional parameters to add to the query
        Returns:
        retrieved SolrDocument, or null if no document is found.
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • getById

        public SolrDocumentList getById​(String collection,
                                        Collection<String> ids)
                                 throws SolrServerException,
                                        IOException
        Retrieves the SolrDocuments associated with the given identifiers. If a document was not found, it will not be added to the SolrDocumentList.
        Parameters:
        collection - the Solr collection to query
        ids - the ids
        Returns:
        a SolrDocumentList, or null if no documents were found
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • getById

        public SolrDocumentList getById​(String collection,
                                        Collection<String> ids,
                                        SolrParams params)
                                 throws SolrServerException,
                                        IOException
        Retrieves the SolrDocuments associated with the given identifiers and uses the SolrParams to execute the request. If a document was not found, it will not be added to the SolrDocumentList.
        Parameters:
        collection - the Solr collection to query
        ids - the ids
        params - additional parameters to add to the query
        Returns:
        a SolrDocumentList, or null if no documents were found
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server
      • getById

        public SolrDocumentList getById​(Collection<String> ids,
                                        SolrParams params)
                                 throws SolrServerException,
                                        IOException
        Retrieves the SolrDocuments associated with the given identifiers and uses the SolrParams to execute the request. If a document was not found, it will not be added to the SolrDocumentList.
        Parameters:
        ids - the ids
        params - additional parameters to add to the query
        Returns:
        a SolrDocumentList, or null if no documents were found
        Throws:
        IOException - If there is a low-level I/O error.
        SolrServerException - if there is an error on the server