gpt4 book ai didi

solr - 如何使用 DataImportHandler 生成 Id?

转载 作者:行者123 更新时间:2023-12-01 10:06:09 24 4
gpt4 key购买 nike

我是 Solr 的新手,我正在努力导入一些不包含 ID 字段的 XML 数据,尽管它是必需的,因为它说我的 schema.xml:

一个 XML 示例:

<results>
<estacions>
<estacio id="72400" nom="Aeroport"/>
<estacio id="79600" nom="Arenys de Mar"/>
...
</estacions>
</results>

架构.xml:

<uniqueKey>id</uniqueKey>

此时,我需要从 http fetch 导入这个 xml,然后我使用 DataimportHandler。这是我的 data-config.xml

<dataConfig>
<dataSource type="URLDataSource" />
<document>
<entity name="renfe"
url="http://host_url/myexample.xml"
processor="XPathEntityProcessor"
forEach="/results/estacions/estacio"
transformer="script:generateCustomId">
<field column="idestacio" xpath="/results/estacions/estacio/@id" commonField="true" />
<field column="nomestacio" xpath="/results/estacions/estacio/@nom" commonField="true" />
</entity>
</document>

然后,它似乎工作正常,但我收到以下错误:org.apache.solr.common.SolrException:[doc=null] 缺少必填字段:id

这让我觉得我应该在导入时通过使用 data-config.xml 生成一个自动 id,但我不知道如何去做。

我该怎么办?使用 ScriptTransformer?有什么想法感激不尽

还有一个问题:我可以在导入过程中强制输入一个值吗?

例如:<field column="site" value="estacions"/> (显然这是行不通的)

最佳答案

您可以使用下面的代码生成 ID:

<dataConfig>
<script><![CDATA[
id = 1;
function GenerateId(row) {
row.put('id', (id ++).toFixed());
return row;
}
]]></script>
<dataSource type="URLDataSource" />
<document>
<entity name="renfe"
url="http://host_url/myexample.xml"
processor="XPathEntityProcessor"
forEach="/results/estacions/estacio"
transformer="script:GenerateId">
<field column="idestacio" xpath="/results/estacions/estacio/@id" commonField="true" />
<field column="nomestacio" xpath="/results/estacions/estacio/@nom" commonField="true" />
</entity>
</document>

关于solr - 如何使用 DataImportHandler 生成 Id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10381298/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com