solr adds an index to the data

Solr adds a single piece of data, no need to say more, just follow the steps.

1. Add a single index, through the code  

// add a piece of data

    public static void addDoc() throws SolrServerException,IOException {
        // Get request
        SolrClient sc = getSolrClient();
        // Assemble text
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("id", 100242);
        doc.addField(" name", "Yin Pengfei");
        doc.addField("gender", "male");
        sc.add(doc);
        sc.commit();

    }

    here url is the path to your solr server

     private static final String url = "http://localhost:8088/solr/new_core";

    public static SolrClient getSolrClient() {
        //Solr's server-side path is configured in project.solr.url in the project.properties file
// return new HttpSolrClient(CenConf.getInstance().getProperty("project.solr.url") );
        return new HttpSolrClient(url);
    }

2. When solr is successfully built, create your own instance, Core Admin--->add Core

 <1> After creating your own instance, click dataimport, and then there is a Configuration on the right side, which is what you need to index after you query the database

<?xml version="1.0" encoding="UTF-8" ?>
<dataConfig>
	<dataSource driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.0.100:3306/talent?characterEncoding=utf-8" user="root" password="root" />
    <document name="document"> 
    	<entity name="person" query="SELECT * from person ">
            <field column="id" name="id" />   
            <field column="name" name="name" /> 
            <entity name="user" query="SELECT * from user where personId = '${person.id}'">
<field column="userid" name="username" />
                 <field column="password" name="password" />
            </entity>
  </ entity >
</ document >
</ dataConfig > This place can configure the database you need to query, the table can be a linked list query.
The work of adding the index has been completed, check these red boxes, and then click execute to execute




At this point, the addition of indexes has been completed. If your solr's tomcat reports an error during the import, it is estimated that your memory is hung up, or the database connection is closed. At this time, you can increase your solr's The jvm parameter of tomcat can be adjusted a little larger

-Xms128m -Xmx800m -XX:PermSize=64M -XX:MaxNewSize=256m -XX:MaxPermSize=128m

-Djava.awt.headless=true

The corresponding parameters here can be set reasonably


Say more here,<field> set in data-config.xml要添加到managed-schema文件中,我的solr是6.4.2版本。可以通过管理端来操作:点击左侧的 Schema 然后add field

也就是说data-config.xml需要创建的索引必须在Schema里面有。设置完毕后,把managed-schema 改成schema.xml




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325855048&siteId=291194637