문제

I want to send an update to solr with a softcommit.

Something like this:

http://xxx:8983/solr/corename/update?softcommit=true

I am working in C# so this is what the code looks like:

public void PostToSolr( string solrXML, SolrCommitType commitType )
    {
        string uri = solrConfig.UpdateURL;  //something like  "http://xxxx:8983/solr/corename/update";

        switch( commitType )
        {
            case SolrCommitType.SOFT:
                uri = uri + "?softcommit=true";
                break;

            case SolrCommitType.HARD:
                uri = uri + "?commit=true";
                break;
        }

        HttpWebResponse response = null;
        WebRequest request = WebRequest.Create( uri );

        try
        {

            request.ContentType = "application/xml";
            request.Method = "POST";
            using( var rs = request.GetRequestStream( ) )
            {
                byte[] byteArray = Encoding.UTF8.GetBytes( solrXML );
                rs.Write( byteArray, 0, byteArray.Length );
            }

            // get response
            response = request.GetResponse( ) as HttpWebResponse;

            HttpStatusCode statusCode = response.StatusCode;

            if( statusCode != HttpStatusCode.OK )
            {
                throw new Exception( String.Format( "HttpStatusCode={0}.", statusCode.ToString( ) ) );
            }
        }
        catch( Exception ex )
        {
            throw new Exception( String.Format( "Uri={0}. Post Data={1}", uri, solrXML ), ex );
        }
        finally
        {
            if( null != response )
            {
                response.Close( );
                response = null;
            }

            request = null;
        }
    }

When I post to SOLR with a softcommit the updated document is not immediately visible. In the solr config I have setup autosoftcommit to occur every minute and so eventually the updated document does become visible.

How can I send a new document via the update and make it immediately visible without doing a commit and re-open the searcher? Is there a way to force a softcommit? Or does softcommits only happen according to the policy set in the config file?

도움이 되었습니까?

해결책

All you need to do is use the parameter softCommit (camel case), this would solve the problem. A sample request would be:

curl http://localhost:8983/solr/collection1/update?softCommit=true -H "Content-Type: text/xml" --data-binary '<add><doc><field name="id">testdoc2</field></doc></add>'

it could be used after documents are added just to commit what isn't commited yet as you tried but using camel case softCommit boolean parameter.

From documentation:

softCommit = "true" | "false" - default is false - perform a soft commit - this will refresh the 'view' of the index in a more performant manner, but without "on-disk" guarantees. Solr (!) 4.0

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top