(三) solr 索引數據導入:json格式


如果我們有一個基於JavaScript的應用需要使用solr,此時再使用xml的格式可能就是一個很好的選擇,因為它太大而且還需要轉換。因此可以采用json,進行相應的處理。

下面就是具體的實現方式:

schema.xml的部分配置如下:

<field name="id" type="string" stored="true" indexed="true"/>
<field name="name" type="string" stored="true" indexed="true" omitNorms="false"/>
<field name="author" type="string" stored="true" indexed="true" multiValued="true"/>

下面是需要准備進行索引的json數據格式,並且需要對某些書籍的書名標識一下它們的重要程度高於其它書籍:books.json

{
"add": {
 "overwrite": true,
"doc": {
  "id": 1,
  "name": "Some book",
  "author": ["John", "Marry"]
 }
}
,
"add": {
 "overwrite": true,
 "boost": 2.5,
 "doc": {
  "id": 2,
  "name": "Important Book",
  "author": ["Harry", "Jane"]
 }
}
,
"add": {
  "overwrite": true,
  "doc": {
  "id": 3,
  "name": "Some other book",
  "author": "Marry"
 }
}
}

 為了能夠將上面的json文檔提交給solr,還需要在solrconfig.xml文件中添加以下配置,為json格式的文檔處理添加一個請求處理方式:

<requestHandler name="/update/json" class="solr.JsonUpdateRequestHandler" />

以上的配置完畢之后,我們可以采用以下的方式開始向solr提交我們剛才的json文檔了

curl http://localhost:8983/solr/update/json --data-binary @books.json -H 'Content-type:text/json; charset=utf-8'

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM