bhucho
bhucho

Reputation: 3420

Error in using Solr to add data - Solr HTTP error: OK (409)(HttpException )

I am trying this out for quite a time now, I have even googled a lot.

I am getting this error while trying to add data into Solr using Solarium in Laravel,

(1/1) HttpException

Solr HTTP error: OK (409)
{
"responseHeader":{
"status":409,
"QTime":3},
"error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"version conflict for 12 expected=12435421423451 actual=-1",
"code":409}}
in Result.php line 106
at Result->__construct(object(Client), object(Query), object(Response))in Client.php line 753

This is my function in EmployeeController.php

public function enterDataSolr()
{

    $update = $this->client->createUpdate();


    $doc1 = $update->createDocument();
    $doc1->Gender = "M";
    $doc1->Salary = 199999;
    $doc1->SSN = "0050-03-10T21:00:00Z";
    $doc1->City = "Mumbai";
    $doc1->State = "Maharastra";
    $doc1->Zip = 119973;
    $doc1->Region = "Navi Mumbai";
    $doc1->Password = "21435t34tgsd";
    $doc1->id = 12;
    $doc1->_Emp_ID = 1234546;
    $doc1->Name_Prefix = "Mr.";
    $doc1->First_Name = "Kant";
    $doc1->Middle_Initial = "S";
    $doc1->Last_Name = "Bhat";
    $doc1->E_Mail = "[email protected]";
    $doc1->Father_s_Name = "Mant";
    $doc1->Mother_s_Name = "Vandana";
    $doc1->Mother_s_Maiden_Name = "vandana";
    $doc1->Date_of_Birth = 12/2/1998;
    $doc1->Time_of_Birth = "12:24";
    $doc1->Age_in_Yrs = 21;
    $doc1->Weight_in_Kgs = 56;
    $doc1->Date_of_Joining = "2/2/2020";
    $doc1->Quarter_of_Joining = "Q1";
    $doc1->Half_of_Joining = "1st";
    $doc1->Year_of_Joining = 2020;
    $doc1->Month_of_Joining = 2;
    $doc1->Month_Name_of_Joining = "February";
    $doc1->Short_Month = "Feb";
    $doc1->Day_of_Joining = 2;
    $doc1->DOW_of_Joining = "Tuesday";
    $doc1->Short_DOW = "Tues";
    $doc1->Age_in_Company__Years_ = 2.4;
    $doc1->Last___Hike = 2;
    $doc1->Phone_No = 8906986022;
    $doc1->Place_Name = "Delhi";
    $doc1->User_Name = "kant";
    $doc1->_version_ = 12435421423451;
    $doc1->score = 1;

    $doc2 = $update->createDocument();
    $doc2->Gender = "F";
    $doc2->Salary = '200000';
    $doc2->SSN = "0050-03-10T00:00:00Z";
    $doc2->City = "Purcellville";
    $doc2->State = "VA";
    $doc2->Zip = 20134;
    $doc2->Region = "South";
    $doc2->Password = "1";
    $doc2->id = "2a69b460-2299-46a6-84b6-cf16938a1997";
    $doc2->_Emp_ID = 520092;
    $doc2->Name_Prefix = "Mrs.";
    $doc2->First_Name = "Mary";
    $doc2->Middle_Initial = "Watson";
    $doc2->Last_Name = "Jane";
    $doc2->E_Mail = "[email protected]";
    $doc2->Father_s_Name = "Spder";
    $doc2->Mother_s_Name = "May";
    $doc2->Mother_s_Maiden_Name = "may";
    $doc2->Date_of_Birth = "10/1/1921";
    $doc2->Time_of_Birth = "12:02";
    $doc2->Age_in_Yrs = 99;
    $doc2->Weight_in_Kgs = 61;
    $doc2->Date_of_Joining = "2/27/2020";
    $doc2->Quarter_of_Joining = "Q2";
    $doc2->Half_of_Joining = "Q1";
    $doc2->Year_of_Joining = "Q4";
    $doc2->Month_of_Joining = "2";
    $doc2->Month_Name_of_Joining = "February";
    $doc2->Short_Month = "Feb";
    $doc2->Day_of_Joining = 27;
    $doc2->DOW_of_Joining = "Tuesday";
    $doc2->Short_DOW = "Tues";
    $doc2->Age_in_Company__Years_ = 1.7;
    $doc2->Last___Hike = "11%";
    $doc2->Phone_No = 852489628962;
    $doc2->Place_Name = "Purcellville";
    $doc2->User_Name = "llwoods";
    $doc2->_version_ = 1658322049611851997;
    $doc2->score = 1;

    $update->addDocuments(array($doc1, $doc2));
    $update->addCommit();
    $result = $this->client->update($update); 

    echo '<b>Update query executed</b><br/>';
    echo 'Query status: ' . $result->getStatus(). '<br/>';
    echo 'Query time: ' . $result->getQueryTime();

}

The connection is made properly as as ping() function is returning status OK. The search function is working properly as well. This is the constructor

 public function __construct(EmployeeRepository $emp_repository, Client $client)
{   
    $this->emp_repository = $emp_repository;
    $this->client = $client;
    //dd('Solarium library version: ' . Client::VERSION . ' - ');

}

and I have used class as well

use Solarium\Client;

Upvotes: 1

Views: 1969

Answers (1)

Abhijit Bashetti
Abhijit Bashetti

Reputation: 8668

Optimistic Concurrency is a feature of Solr that can be used by client applications which update/replace documents to ensure that the document they are replacing/updating has not been concurrently modified by another client application.

If there is a version conflict (HTTP error code 409), the client starts the process over.

This feature works by requiring a _version_ field on all documents in the index, and comparing that to a version specified as part of the update command. By default, Solr’s Schema includes a _version_ field, and this field is automatically added to each new document.

$ curl -X POST -H 'Content-Type: application/json' 'http://localhost:8983/solr/techproducts/update?_version_=1632740120218042368&versions=true&commit=true&omitHeader=true' --data-binary '
[{ "id" : "aaa",
   "foo_s" : "update attempt with correct existing version" }]'

an update with a value for _version_ that matches the value in the index, and it succeeds. Because we included versions=true to the update request, the response includes a different value for the _version_ field.

If an update with a value for _version_ embedded in the document itself. The request fails because you have specified the wrong version. Below would be the error for it.

{
  "error":{
    "metadata":[
      "error-class","org.apache.solr.common.SolrException",
      "root-error-class","org.apache.solr.common.SolrException"],
    "msg":"version conflict for aaa expected=100 actual=1632740462042284032",
    "code":409
    }
}

Please refer the solr documentation for more details.

The -1 here is meant that Solr is not able to find a document with that version. I would suggest you to try sending one of the document to solr yourself by hand on the Solr admin UI. Select your core/collection name, then click the Documents link(on the solr admin page) and you'll be at the page where you could send the document for update to solr.

Solr Document Update

Upvotes: 2

Related Questions