json - Solr:如何在 JSON 和 CSV 导入期间指定模式?

标签 json csv solr

我是 Solr 的新手,我正在尝试测试它的功能。我来自 RDBMS 世界,想知道 Solr 将如何处理我的数据。

我创建了一个新核心:

$ bin/solr create -c test

并使用以下方法成功加载了一个 JSON 文件:

$ bin/post -c test file.json

file.json 的第一条记录如下所示:

{"attr":"01234"}

但 Solr 将其存储为:

{"attr":1234}

我在 this tutorial (Youtube video) 之后开始定义数据导入处理程序为了正确存储我的数据,发现DIH无法处理JSON。我坚持 data-config.xml 的定义,因为教程使用 XPathEntityProcessor 处理 XML 文件,但找不到 JSON 甚至 CSV 处理器(我可以轻松检索 file.json 的 CSV 版本,因此加载 CSV 或 JSON 对我来说是一样的)。官方文档有点乱,没有提供很多有用的例子。可能处理 JSON 和 CSV 文档的唯一处理器是 LineEntityProcessorPlainTextEntityProcessor ( Official Documentation )。

This other link来自 Solr Wiki 状态:

Goals

...

Make it possible to plugin any kind of datasource (ftp,scp etc) and any other format of user choice (JSON,csv etc)

所以我想这真的有可能,但是怎么做呢?

我找到了一个 similar question 2014 年发布,这里没有人回答,所以想知道在 2016 年,随着 Solar 的更新版本,这个问题是否有一个众所周知的解决方案。

那么问题来了:如何使用特定的数据模式导入 JSON 和 CSV 文档?

更新

执行 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>
...

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 发行版中,有一个电影示例(在 example/films 中)展示了如何索引 JSON 并利用精确字段定义和类型自动检测。说明 (README.txt) 包括您在忘记执行其中一个步骤时将会看到的结果。

我建议您试验一下,然后将这些知识应用到您自己的用例中。

关于json - Solr:如何在 JSON 和 CSV 导入期间指定模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39726403/

相关文章:

java - Gson - 从 Json 转换为类型化的 ArrayList<T>

java - Json同名序列化和反序列化

mysql 无法使用 load data local 导入以\r\n\r\n 结尾的 csv 行

tomcat - 如何调试不返回记录的solr查询

json - 在 Swift 上访问变量 do-catch 语句

ruby-on-rails - 如何在没有根 key 的情况下解析 JSON

javascript - 删除一行 csv 或忽略它

regex - golang正则表达式删除csv文件中的字段中的双引号

xml - 在没有字段规范的情况下在 SOLR 7 上索引整个 XML 文档

Solr 自定义相似度