Solr 5.3更新查询VS Solr 3.6(使用php-ccurl和json)


Solr 5.3 update query VS Solr 3.6 ( using php curl and json)

在服务器上设置solr 3.6之前,我开始使用Bitnami solr Stack 5.0。

以下是我过去如何索引我的数据:

    $ch = curl_init(SOLR_HOST . SOLR_CORE_PRODUCTS . "/update?wt=json&commitWithin=4000&debugQuery=true&overwrite=&true&commit=true");
    $json = array(array("Field" => "value", "Field2" => "value2"));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $js);
    $response = curl_exec($ch);

现在,让我们关注Solr的人

Solr 3.1 示例

Solr 3.2是第一个支持JSONObject语法数组的版本,因此在Solr 3.1中,需要使用重复的名称("add"标记)一次添加多个文档。在JSON中,名称重复是合法的。示例:

curl http://localhost:8983/solr/update/json -H 'Content-type:application/json' -d '
{
 "add": {"doc": {"id" : "TestDoc1", "title" : "test1"} },
 "add": {"doc": {"id" : "TestDoc2", "title" : "another test"} }
}'

我经历了:

    $ch = curl_init(SOLR_HOST . SOLR_CORE_PRODUCTS . "/update?wt=json&commitWithin=4000&debugQuery=true&overwrite=&true&commit=true");
    $json = array("add: " => array("doc:" =>array("Field" => "value", "Field2" => "value2")));
    $js = json_encode($json);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $js);
    $response = curl_exec($ch);

会胜任这项工作$js的值为:{"add: ":{"doc:":{"Field":"value","Field2":"value2"}}}

错误是:

message序言中出现意外字符"{"(代码123);[行,列{未知源}]处应为"<":[1,1]

有什么想法吗?

看起来您正在使用XML更新处理程序。尝试将您的json发布到:

curl -X POST 'http://localhost:8983/solr/update/json?commit=true' -H 'Content-type:application/json; charset=UTF-8' --data @data.json

在solrconfig.xml中查看正确的请求处理程序,在Solr 3.6上,您会有一个如下的条目:

<requestHandler name="/update/csv" class="solr.CSVRequestHandler" startup="lazy"/>

如果你检查Solr日志,你应该会看到一个异常,比如:

SEVERE: org.apache.solr.common.SolrException: Unexpected character '{' (code 123) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
        at org.apache.solr.handler.XMLLoader.load(XMLLoader.java:81)

很明显,XML处理程序正在被调用。

只有在Solr>4.*版本上,更新处理程序才能从流中确定数据类型。