我是Solr的新手,我正在尝试测试它的功能。 我来自RDBMS世界,并想知道Solr将如何处理我的数据。
我创建了一个新核心:
$ bin/solr create -c test
并使用以下命令成功加载了JSON文件:
$ bin/post -c test file.json
file.json的第一条记录如下所示:
{"attr":"01234"}
但Solr将其存储为:
{"attr":1234}
我开始按照本教程(Youtube视频)定义数据导入处理程序,以便正确存储我的数据,并发现DIH无法处理JSON。 我坚持使用data-config.xml的定义,因为该教程使用XPathEntityProcessor处理XML文件,但找不到JSON甚至CSV处理器(我可以轻松检索到file.json的CSV版本,所以加载一个CSV或JSON对我来说是一样的)。 官方文档有点乱,并没有提供很多有用的例子。 可能处理JSON和CSV文档的单独处理器是LineEntityProcessor和PlainTextEntityProcessor ( 官方文档 )。
来自Solr Wiki的另一个链接指出:
目标
...
可以插入任何类型的数据源(ftp,scp等)和任何其他用户选择格式( JSON , csv等)
所以我猜这真的有可能,但是怎么样?
我在2014年发现了一个类似的问题 ,没有人在这里回答,所以想知道在2016年,对于更新版本的Solar,有一个众所周知的解决方案。
所以问题是:如何使用特定的数据模式导入JSON和CSV文档?
UPDATE
执行http://localhost:8983/solr/test/dihupdate?command=full-import不会触发任何错误,但不会加载任何文档。 以下是位于核心目录中的各种xml文件:
solrconfig.xml
... <schemaFactory class="ClassicIndexSchemaFactory" /> ... <requestHandler name="/dihupdate" class="org.apache.solr.handler.dataimport.DataImportHandler" startup="lazy"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler> ...UPDATE
Executing http://localhost:8983/solr/test/dihupdate?command=full-import doesn't trigger any error but doesn't load any document. Here are the various xml files located in the core directory:
solrconfig.xml
... <schemaFactory class="ClassicIndexSchemaFactory" /> ... <requestHandler name="/dihupdate" class="org.apache.solr.handler.dataimport.DataImportHandler" startup="lazy"> <lst name="defaults"> <str name="config">data-config.xml</str> </lst> </requestHandler> ...schema.xml
... <field name="id" type="long" indexed="true" stored="true" required="true" multiValued="false" /> <field name="attr1" type="string" indexed="true" stored="true" required="true" multiValued="true" /> <field name="date" type="date" indexed="true" stored="false" multiValued="true" /> <field name="attr2" type="string" indexed="true" stored="true" multiValued="true" /> <field name="attr3" type="string" indexed="true" stored="true" multiValued="true" /> <field name="attr4" type="int" indexed="false" stored="true" multiValued="true" /> <uniqueKey>id</uniqueKey> ...data-config.xml
<dataConfig> <dataSource type="FileDataSource" /> <document> <entity name="f" processor="FileListEntityProcessor" fileName="test.json" rootEntity="false" dataSource="null" recursive="true" baseDir="/path/to/data/"/> </document> </dataConfig>最满意答案
在Solr发行版中,有一个电影示例(在示例/电影中 ),它展示了如何索引JSON并利用精确的字段定义和类型自动检测。 说明( README.txt )包括您在忘记执行其中一个步骤时将看到的结果。
我建议你试验一下,然后将这些知识应用到你自己的用例中。
In the Solr distribution, there is a films example (in example/films) that shows how to index JSON and takes advantage of both exact field definitions and type auto-detect. The instructions (README.txt) include the results you will see if you forget to do one of the steps as well.
I suggest you experiment with that and then apply that knowledge to your own use case.
更多推荐
JSON,Solr,CSV,电脑培训,计算机培训,IT培训"/> <meta name="description&quo
发布评论