在 solr 中从 JSON 导入数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14705258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
import data from JSON in solr
提问by Sagar Joshi
Currently I am using XML file in solr. I index xml file's data using DataimportHandler with XPathentityProcessor.
目前我在 solr 中使用 XML 文件。我使用 DataimportHandler 和 XPathentityProcessor 索引 xml 文件的数据。
Now I want to import data from json file.
现在我想从 json 文件导入数据。
Is there any example ?
有什么例子吗?
Regards, Sagar
问候, 萨加尔
回答by Tonko Mulder
What you need is something like
你需要的是类似的东西
curl 'http://localhost:8983/solr/update/json?commit=true' --data-binary @books.json -H 'Content-type:application/json'
Taken from the example.
取自示例。
回答by Alexandre Rafalovitch
DataImportHandler does not allow you to use JSON as a source. The only way is to use Update Handler which can handle JSON natively. But that has to be in the JSON structure Solr expects(array of hashes or hash of command/hashes).
DataImportHandler 不允许您使用 JSON 作为源。唯一的方法是使用可以原生处理 JSON 的 Update Handler。但这必须在Solr 期望的 JSON 结构中(散列数组或命令/散列散列)。
回答by Shrey Shivam
if you dont want to use curl command, you can fire the command directly on the browser and get the desired result:
如果不想使用 curl 命令,可以直接在浏览器上触发该命令并获得所需的结果:
http://localhost:8983/solr/update/json?commit=true --data-binary @books.json -H 'Content-type:application/json'
http://localhost:8983/solr/update/json?commit=true --data-binary @books.json -H 'Content-type:application/json'
Put the json file in /example/exampledocs folder.This is default directory path in solr. If you are using java or php etc then there are several classes and methods that you use and then you wont require to mention the entire command as above.Is that what you were asking for?
将 json 文件放在 /example/exampledocs 文件夹中。这是 solr 中的默认目录路径。如果您使用的是 java 或 php 等,那么您使用了几个类和方法,然后您就不需要像上面那样提及整个命令。这是您要的吗?
回答by Philippe Moore
You can also update your docs by including the ?commit=true statement within the url of a curl command like so.
您还可以通过在 curl 命令的 url 中包含 ?commit=true 语句来更新您的文档,如下所示。
curl -X POST -H "Content-Type: application/json" -u "{usernamne}":"{password}" "https://your_host/solr/your_collection/update/json?commit=true" --data-binary @/path/to/your/data/your_data.json
回答by freedev
If you want import part or the entire collection from a json format, well, there is an alternative.
如果您想从 json 格式导入部分或整个集合,那么还有一种替代方法。
I wrote a java tool: https://github.com/freedev/solr-import-export-json
我写了一个java工具:https: //github.com/freedev/solr-import-export-json
This is a java application that imports and exports a Solr collection using SolrJ. Every document has to be a json object and in the file you are importing you must have a list of lines whereas each line is a json object.
这是一个 Java 应用程序,它使用SolrJ. 每个文档都必须是一个 json 对象,并且在您要导入的文件中,您必须有一个行列表,而每一行都是一个 json 对象。
{ "id": 1, "date": "20160101T00:00:00", "text": "some text" }
{ "id": 2, "date": "20160102T00:00:00", "text": "some text" }
{ "id": 3, "date": "20160103T00:00:00", "text": "some text" }
I haven't tried with nested documents, and the keys of json document should be exactly the names of the Solr fields.
我没试过嵌套文档,json 文档的键应该是 Solr 字段的名称。
回答by Shobhit_Geek
You can use REST api to send data to Solr. Please use this path:
您可以使用 REST api 将数据发送到 Solr。请使用此路径:
localhost:8983/solr/simple2/update?commit=true
//(simple2 is the core name and localhost:8983 is server path.)
and you have to define
你必须定义
:content_type => 'application/json'
in request header.Along with it you can send json file/data to solr using post request.
在请求标头中。连同它,您可以使用 post 请求将 json 文件/数据发送到 solr。
For more information you can visit http://geekdirt.com/blog/indexing-in-solr-using-json-and-rest-apis/
有关更多信息,您可以访问http://geekdirt.com/blog/indexing-in-solr-using-json-and-rest-apis/

