Bad requests with Solr-PHP-Client, good with Curl

2,568 views
Skip to first unread message

Dotan Cohen

unread,
Oct 18, 2012, 2:27:55 PM10/18/12
to php-sol...@googlegroups.com
Consider this successful Solr commit:

$ curl http://someAddress:8983/solr/update?commit=true -H
"Content-Type: text/xml" --data-binary '<add><doc><field
name="id">abcd</field><field name="text">This is a
test.</field></doc></add>'
<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int
name="QTime">166</int></lst>
</response>



However, this code in PHP fails:
#!/usr/bin/php -q
$ cat solrTest.php
<?
require_once('/home/dotancohen/SolrPhpClient/Apache/Solr/Service.php');

$solr = new Apache_Solr_Service('someAddress', 8983, '/solr');
$doc = new Apache_Solr_Document();
$doc->id = "efgh";
$doc->text = "This is a test from PHP.";
$documents[] = $doc;

try {
$solr->addDocuments( $documents );
$solr->commit();
$solr->optimize();
} catch(Exception $e) {
echo $e->getMessage();
}

?>
$ ./solrTest.php
'400' Status: Bad Request

I stress that the 'id' field is of type 'string'. Why might the curl
command work, but PHP not? I have used this Solr-Php-Client library to
access other Solr clients before, so I know that it does work and is
configured properly.

Thanks.

--
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com

Dotan Cohen

unread,
Oct 18, 2012, 3:08:42 PM10/18/12
to php-sol...@googlegroups.com
Going through the Solr logs, it seems that this is written to the logs
each time I try to make a request with Solr-Php-Client:

21:04:39 WARNING XMLLoader Unknown attribute id in add:allowDups
21:04:39 WARNING XMLLoader Unknown attribute id in add:overwritePending
21:04:39 WARNING XMLLoader Unknown attribute id in add:overwriteCommitted
21:04:40 SEVERE SolrCore org.apache.solr.common.SolrException:
Unknown commit parameter 'waitFlush'

Note that I am using a unique 'id' for each request. Certainly the
field 'id' is known. What are the allowDups, overwritePending, and
overwriteCommitted elements (assuming that they are XML elements as
they have attributes).

Donovan Jimenez

unread,
Oct 18, 2012, 4:50:43 PM10/18/12
to php-sol...@googlegroups.com
which methid is the exception thrown from?

addDocuments(...)

or

commit()

or

optimize()

what solr version are you using? what version of the php client are  you using?

Donovan

--
You received this message because you are subscribed to the Google Groups "PHP Solr Client" group.
To post to this group, send email to php-sol...@googlegroups.com.
To unsubscribe from this group, send email to php-solr-clie...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/php-solr-client?hl=en.


Dotan Cohen

unread,
Oct 18, 2012, 5:03:58 PM10/18/12
to php-sol...@googlegroups.com
On Thu, Oct 18, 2012 at 10:50 PM, Donovan Jimenez
<donovan...@gmail.com> wrote:
> which methid is the exception thrown from?
>

I added try/catches around each method individually. Both commit() and
optimize() threw the same exception:
'400' Status: Bad Request

> what solr version are you using? what version of the php client are you
> using?
>

Solr 4.

The changelog has this date in the first line: 2011-02-08 20:38
From looking at the Solr-Php-Client page on Google Code, there was
only one release after that date, so this looks like the latest
version.

Donovan Jimenez

unread,
Oct 18, 2012, 5:08:32 PM10/18/12
to php-sol...@googlegroups.com
See this issue: http://code.google.com/p/solr-php-client/issues/detail?id=75

waitFlush was removed in solr 4.0, and it has not been fixed in client trunk yet.

I'll try to fix this soon. In the mean time you can edit the commit and optimize methods to not put waitFlush attribute in the xml.

Donovan

Dotan Cohen

unread,
Oct 18, 2012, 5:15:33 PM10/18/12
to php-sol...@googlegroups.com
On Thu, Oct 18, 2012 at 11:08 PM, Donovan Jimenez
<donovan...@gmail.com> wrote:
> See this issue: http://code.google.com/p/solr-php-client/issues/detail?id=75
>
> waitFlush was removed in solr 4.0, and it has not been fixed in client trunk
> yet.
>
> I'll try to fix this soon. In the mean time you can edit the commit and
> optimize methods to not put waitFlush attribute in the xml.
>

Thanks. I found the commit method defined in these two files:
Apache/Solr/Service.php
Apache/Solr/Service/Balancer.php

The two have slightly different signatures, but the $waitFlush
parameter is the second of them both, and it defaults to true in both.
Should I just change that default to false?

Donovan Jimenez

unread,
Oct 18, 2012, 5:20:21 PM10/18/12
to php-sol...@googlegroups.com
no, you want to remove the attribute in the XML construction.... remove " waitFlush="' . $flushValue . '

from

$rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitFlush="' . $flushValue . '" waitSearcher="' . $searcherValue . '" />';

optimize will have a similar section

Donovan

Dotan Cohen

unread,
Oct 18, 2012, 5:31:09 PM10/18/12
to php-sol...@googlegroups.com
On Thu, Oct 18, 2012 at 11:20 PM, Donovan Jimenez
<donovan...@gmail.com> wrote:
> no, you want to remove the attribute in the XML construction.... remove "
> waitFlush="' . $flushValue . '
>
> from
>
> $rawPost = '<commit expungeDeletes="' . $expungeValue . '" waitFlush="' .
> $flushValue . '" waitSearcher="' . $searcherValue . '" />';
>
> optimize will have a similar section
>
> Donovan
>

Thank you Donovan!

I've got to say, not only is your library very helpful, but your
support on the mailing list is very helpful. Just about 2 hours after
my first post on the issue, we've got the whole thing sorted out, with
code changes. Most commercial entities that one deals with won't even
respond with a form letter within two hours!

Thank you very much Donovan. You are much appreciated.

Dotan Cohen

unread,
Oct 18, 2012, 5:50:24 PM10/18/12
to php-sol...@googlegroups.com
In some critical scripts that I'm converting from Solr 3 to Solr 4,
I'm writing to both like this:

$solr = new Apache_Solr_Service('index.websolr.com', 80, '/solr/someId');
$solr4 = new Apache_Solr_Service('index.websolr.com', 80, '/solr/someId4');

The method change will break the Solr 3 code. Thus, can I simply make
another two methods commit4() and optimize4() and call that on the
Solr 4 instance:

$solr->commit();
$solr->commit();
$solr4->optimize4();
$solr4->optimize4();

I see that other functions internal to Solr-Php-Client do call
commit() and optimize(), that is why I ask if this is safe to do.

Thanks.

Donovan Jimenez

unread,
Oct 18, 2012, 5:59:45 PM10/18/12
to php-sol...@googlegroups.com
That seems like a reasonable workaround for now. 

Dotan Cohen

unread,
Oct 18, 2012, 6:31:10 PM10/18/12
to php-sol...@googlegroups.com
On Thu, Oct 18, 2012 at 11:59 PM, Donovan Jimenez
<donovan...@gmail.com> wrote:
> That seems like a reasonable workaround for now.
>

Great, thanks.

Anthony Tran

unread,
Nov 27, 2012, 2:30:32 AM11/27/12
to php-sol...@googlegroups.com
Really thanks Donovan you're support so helpful. We appreciated that !

Vào 04:31:10 UTC+7 Thứ sáu, ngày 19 tháng mười năm 2012, Dotan Cohen đã viết:

Anthony Tran

unread,
Nov 27, 2012, 2:32:33 AM11/27/12
to php-sol...@googlegroups.com
Yeah great...great....thanks !

Fabio Salomoni

unread,
Feb 28, 2013, 7:22:22 AM2/28/13
to php-sol...@googlegroups.com

Naga Sundaram

unread,
Aug 21, 2013, 10:27:51 AM8/21/13
to php-sol...@googlegroups.com, salomo...@gmail.com
Hi , 
 allowDups,overwritePending,overwriteCommitted are  deprecated .
 please refer the following link . http://wiki.apache.org/solr/UpdateXmlMessages#Optional_attributes_for_.22add.22 

So just update your service.php by follwoing lines

  in "addDocuments" function your prev code is looks like below

old Code: $rawPost = '<add allowDups="' . $dupValue . '" overwritePending="' . $pendingValue . '" overwriteCommitted="' . $committedValue . '">'; 

 Now update like following line...

New Code: $rawPost = '<add>'; .

 i Hope it helps.

Ritesh Upadhyay

unread,
Sep 25, 2013, 5:19:19 AM9/25/13
to php-sol...@googlegroups.com
Hi,
thanks for giving ans for this point its a right one.

Naresh

unread,
Feb 12, 2014, 6:30:40 AM2/12/14
to php-sol...@googlegroups.com

Hi,

Thanks for the previous replies it saved for me so much of time...



when i starts the apache solr server its giving this warnings...

plzz help me

Thanks
Naresh.

Barry Adams

unread,
Nov 17, 2014, 9:51:16 AM11/17/14
to php-sol...@googlegroups.com, salomo...@gmail.com


On Wednesday, 21 August 2013 15:27:51 UTC+1, Naga Sundaram wrote:
Hi , 
 allowDups,overwritePending,overwriteCommitted are  deprecated .
 please refer the following link . http://wiki.apache.org/solr/UpdateXmlMessages#Optional_attributes_for_.22add.22 

So just update your service.php by follwoing lines

  in "addDocuments" function your prev code is looks like below

old Code: $rawPost = '<add allowDups="' . $dupValue . '" overwritePending="' . $pendingValue . '" overwriteCommitted="' . $committedValue . '">'; 

 Now update like following line...

New Code: $rawPost = '<add>'; .

 i Hope it helps.

what i did was to use the new overwrite option to replace the functionity of allowDups

public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0)
    {
#        $dupValue = $allowDups ? 'true' : 'false';
        $overwrite = $allowDups ? 'false':'true';
        $pendingValue = $overwritePending ? 'true' : 'false';
        $committedValue = $overwriteCommitted ? 'true' : 'false';
       
        $commitWithin = (int) $commitWithin;
        $commitWithinString = $commitWithin > 0 ? " commitWithin=\"{$commitWithin}\"" : '';
       
#        $rawPost = "<add allowDups=\"{$dupValue}\" overwritePending=\"{$pendingValue}\" overwriteCommitted=\"{$committedValue}\"{$commitWithinString}>";
        # Changed to work with Solr >4.0
        $rawPost = "<add overwrite=\"{$overwrite}\" {$commitWithinString}>";
        $rawPost .= $this->_documentToXmlFragment($document);
        $rawPost .= '</add>';
        return $this->add($rawPost);
    }

 

prabhat kumar singh

unread,
Apr 19, 2015, 10:32:42 PM4/19/15
to php-sol...@googlegroups.com, salomo...@gmail.com
Hi,

I think, this issue is still there.
Can you please help with the location of Apache/Service.php file which you are advicing to edit.

best
Prabhat

Naga Sundaram

unread,
Apr 20, 2015, 2:27:58 AM4/20/15
to php-sol...@googlegroups.com, salomo...@gmail.com
Hi,

In  Apache/Service.php line:667

Need to update below function

I believe this is your current function

public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
{
$dupValue = $allowDups ? 'true' : 'false';
$pendingValue = $overwritePending ? 'true' : 'false';
$committedValue = $overwriteCommitted ? 'true' : 'false';

$rawPost = '<add allowDups="' . $dupValue . '" overwritePending="' . $pendingValue . '" overwriteCommitted="' . $committedValue . '">';
$rawPost .= $this->_documentToXmlFragment($document);
$rawPost .= '</add>';

return $this->add($rawPost);
}


allowDups,overwritePending,overwriteCommitted are  deprecated .
 please refer the following link . http://wiki.apache.org/solr/UpdateXmlMessages#Optional_attributes_for_.22add.22  

So we need to update function like below

public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true)
{

$rawPost = '<add>';
$rawPost .= $this->_documentToXmlFragment($document);
$rawPost .= '</add>';

return $this->add($rawPost);
}


Hope it will helps :)

--
You received this message because you are subscribed to a topic in the Google Groups "PHP Solr Client" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/php-solr-client/_KX_J6vW2b8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to php-solr-clie...@googlegroups.com.

To post to this group, send email to php-sol...@googlegroups.com.



--
Your's,
E.Nagasundaram B.Tech
Web Designer & Developer
Contact:9025037153

Reply all
Reply to author
Forward
0 new messages