Solr Dataimport嵌套实体

问题描述

我想用dataimporthandler创建嵌套实体。 我使用Solr 8.6,Postgress 12,openjdk-11。

我的配置(schema.xml)如下:

<schema name="products" version="1.5">

    <field name="_version_" type="long" indexed="true" stored="true"/>
    <field name="_root_" type="int" indexed="true" stored="true" required="false"/>

    <uniqueKey>id</uniqueKey>

    <field name="id" type="int" indexed="true" stored="true" multiValued="false"/>
    <field name="name" type="text_ws" indexed="true" stored="true"/>
    <field name="price" type="float" indexed="true" stored="true"/>
    <field name="categories" type="int" indexed="false" stored="true" required="true" multiValued="true"/>

    <field name="pictures" type="string" indexed="false" stored="true" multiValued="true"/>
    <field name="alt" type="string" indexed="false" stored="true"/>
    <field name="title" type="string" indexed="false" stored="true"/>
</schema>

data-config.xml

<dataConfig>
    <dataSource type="JdbcDataSource"
            driver="org.postgresql.Driver"
            url="jdbc:postgresql://${db.host}/myDB"
            user="user"
            password="myPassword"
    />

    <document>
        <entity name="products"
            pk="id"
            transformer="DateFormatTransformer"
            query="SELECT * from products"
            deltaQuery="SELECT id FROM products WHERE updated > '${dataimporter.last_index_time}'::timestamp"
            deltaimportQuery="SELECT * FROM products WHERE id=${dataimporter.delta.id}"
        />

            <field column="id" name="id"/>
            <field column="name" name="name"/>
            <field column="price" name="price"/>

            <entity name="categories"
                query="SELECT category_id FROM product_category WHERE product_id='${products.id}'">
                <field column="category_id" name="categories"/>
            </entity>

            <entity name="pictures"
                    query="SELECT * FROM pictures WHERE product_id='${products.id}'"
                    deltaQuery="SELECT id FROM pictures"
                    deltaimportQuery="SELECT * FROM products WHERE id=${dataimporter.delta.id}"
                    child="true"
                    pk="id"
            >
                <field column="id" name="id"/>
                <field column="alt" name="alt"/>
                <field column="title" name="title"/>
            </entity>
        </entity>
    </document>
</dataConfig>

这是我期望的结果:

[
  {
    "id":1,"name": "name","price": 10,"categories": [1,2]
    "pictures": [
        {
           "id":1,"alt":"alt1"
           "title": "title1"
        },{
           "id":2,"alt":"alt2"
           "title": "title2"
        },]
    "_version_":1674819829308063744
  }
]

现在我将以调试模式开始完全导入

{
   "responseHeader": {
      "status": 0,"QTime": 555
   },"initArgs": [
      "defaults",[
         "config","data-config.xml"
      ]
  ],"command": "full-import","mode": "debug","documents": [
     {
        "price": 1000,"id": 1,"updated": "2020-08-18T07:41:04.758Z","categories": [
           1,2
        ],"_version_": 1675393336193581000,"_root_": "1","_childDocuments_": []
     },]
}

然后我选择获得的所有产品

"response":{"numFound":6,"start":0,"numFoundExact":true,"docs":[
  {
    "alt":"alt1","id":1,"title":"title1","_root_":1,"_version_":1675393336193581056},{
    "alt":"alt2","id":2,"title":"title2",{
    "price":1000.0,"name":"name","updated":"2020-08-18T07:41:04.758Z","categories":[1,2],"_version_":1675393336193581056,"_root_":1},]
 }

如何将图片实体保存到产品实体中或选择带有子实体的产品?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)