简体   繁体   English

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

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

Before setting up solr 3.6 on my server, I started to work on Bitnami Solr Stack 5.0. 在服务器上设置solr 3.6之前,我开始在Bitnami Solr Stack 5.0上工作。

Here is how I used to index my data : 这是我过去为数据编制索引的方式:

    $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);

Now, let's focus on Solr's man 现在,让我们专注于Solr的男人

Solr 3.1 Example Solr 3.1示例

Solr 3.2 was the first version to support the array-of-JSONObject syntax, so in Solr 3.1 one needs to use duplicate names (the "add" tag) to add more than one document at once. Solr 3.2是第一个支持JSONObject语法数组的版本,因此在Solr 3.1中,需要使用重复的名称(“ add”标记)一次添加多个文档。 It is legal in JSON to have duplicate names. JSON中具有重复名称是合法的。 Example: 例:

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"} }
}'

I throught that : 我认为:

    $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);

would do the job. 会做的工作。 $js has the value : {"add: ":{"doc:":{"Field":"value","Field2":"value2"}}} $ js的值是: {"add: ":{"doc:":{"Field":"value","Field2":"value2"}}}

And the error is : 错误是:

message Unexpected character '{' (code 123) in prolog; 消息序言中的意外字符'{'(代码123); expected '<' at [row,col {unknown-source}]: [1,1] [row,col {unknown-source}]的预期'<':[1,1]

Any ideas ? 有任何想法吗 ?

Looks like you are using the XML update handler. 看起来您正在使用XML更新处理程序。 Try posting your json to: 尝试将json发布到:

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

Look in solrconfig.xml to check the correct request handler, on Solr 3.6 you'll have an entry like this: 查看solrconfig.xml以检查正确的请求处理程序,在Solr 3.6上,您将具有以下条目:

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

If you check the Solr logs you should see an exception like: 如果检查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)

and here it is clear that the XML handler is being called. 很明显,这里正在调用XML处理程序。

It was only on versions of Solr > 4.* that the update handler can determine the data type from the stream. 只有在Solr> 4. *的版本上,更新处理程序才能从流中确定数据类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM