【问题标题】:Solr 5.3 update query VS Solr 3.6 ( using php curl and json)Solr 5.3 更新查询 VS Solr 3.6(使用 php curl 和 json)
【发布时间】:2015-12-01 14:31:59
【问题描述】:

在我的服务器上设置 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"}}}

错误是:

消息序言中出现意外字符“{”(代码 123); [row,col {unknown-source}] 处的预期“

有什么想法吗?

【问题讨论】:

    标签: php json curl solr


    【解决方案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.* 的版本上,更新处理程序才能确定流中的数据类型。

    【讨论】:

      猜你喜欢
      • 2023-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-17
      相关资源
      最近更新 更多