Solr: How to import json files using ?

2019-07-09 05:19发布

问题:

I am trying to import via EmbeddedSolr a bunch of json files. The configuration in solrconfig.xml for the import is:

 <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
      <str name="config">src/main/resources/solr-data/data-config.xml</str>
    </lst>
  </requestHandler>

and the data-config.xml is:

<dataConfig>
    <dataSource type="FileDataSource" />
    <document>
        <entity name="f" processor="FileListEntityProcessor"
                fileName=".*json"
                rootEntity="false"
                dataSource="null"
                recursive="true"
                baseDir="src/main/resources/solr-data/"/>
    </document>
</dataConfig>

This is how I generate the index programmatically:

System.setProperty("solr.solr.home", "multicore");
        File home = new File( "src/main/resources/solr" );
        File f = new File( home, "solr.xml" );
        CoreContainer  container = CoreContainer.createAndLoad( "src/main/resources/solr", f );

        EmbeddedSolrServer server = new EmbeddedSolrServer(container, "my_core" );

        SolrQuery importQuery = new SolrQuery();
        importQuery.setRequestHandler("/dataimport");
        importQuery.setParam("command", "full-import");
        importQuery.setParam("entity", "f");
        server.query(importQuery).getResponse();

        SolrQuery qry = new SolrQuery();
        qry.setRequestHandler("solr/my_core");
        qry.setParam("q", "*:*");
        System.out.println (server.query(qry).getResults().toString());

Once I triggered the import via URL, I can see that the import has been triggered, but the files don't get loaded so the index is still empty.

How can I import that files?

标签: json solr