当前位置:网站首页>03_Solr之dataimport
03_Solr之dataimport
2022-07-05 13:54:00 【全栈程序员站长】
solr的主要核心还是数据,那么如何将数据库中的我们需要通过solr分析的数据导入到solr中呢?接下来我们将来学习如何通过配置文件的方式,获取数据库的数据,并导入solr。
这里使用的是mysql测试。
1、先在mysql中建一个库:solr
常见一张表,命名为products,表结构如下:
2、插入一些测试数据:
做好准备工作之后,接下来我们就开始进行solr的链接数据库的相关配置:
1 想要通过配置文件连接数据库,就要有数据库驱动,我这里用的是Mysql。
除了数据库驱动,还需要solr自带的两个jar文件,这两个jar文件主要是用来把数据库数据导入solr服务器的,都在该目录下:
一共三个jar包,都复制粘贴到 solr-7.3.1\server\solr-webapp\webapp\WEB-INF\lib
进入solr-7.3.1\server\solr\test_Core\conf 找到solrconfig.xml 文件,打开,
添加如下配置:
<!--数据库配置 -->
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler> 保存后,在同级目录下,创建data-config.xml文件,该文件主要是配置数据库和配置SQL语句的:
打开添加如下配置:
配置managed-schema中的数据库列和名称的映射关系。
将下列代码复制到managed-schema中:
商品document的field包括:pid、pname、sort_id、sort_name、sale_price、pinfo、pic
先定义Fieldtype:
solr本身提供的fieldtype类型够用了不用定义新的了。
pid:商品id主键
使用solr本身提供的:
<field name="id"type="string" indexed="true" stored="true"required="true" multiValued="false" />
pname:商品名称
<field name="product_name"type="text_ik" indexed="true" stored="true"/>
sort_id:商品分类
<field name="product_sort_id"type="string" indexed="true" stored="true"/>
sort_name:商品分类名称
<fieldname="product_sort_name" type="text_ik"indexed="true" stored="true"/>
sale_price:商品价格
<fieldname="product_sale_price" type="pfloat" indexed="true"stored="true"/>
desc:商品描述
<fieldname="product_desc" type="text_ik"indexed="true" stored="false"/>
pic:商品图片
<field name="product_pic"type="string" indexed="false" stored="true"/>至此,相关配置已经处理完成啦!下面开始导入数据:
去solr-7.3.1/bin下启动solr:
在浏览器输入 localhost:8983/solr 进入后,找到自己的core 然后根据下图进行数据导入:
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/111281.html原文链接:https://javaforall.cn
边栏推荐
- Apicloud studio3 WiFi real machine synchronization and WiFi real machine preview instructions
- matlab学习2022.7.4
- Jetpack Compose入门到精通
- 基于微信小程序的订餐系统
- What about data leakage? " Watson k'7 moves to eliminate security threats
- [js] basic syntax - for loop
- [machine learning notes] how to solve over fitting and under fitting
- PHP character capture notes 2020-09-14
- Leetcode array question brushing notes
- PHP basic syntax
猜你喜欢

Attack and defense world crypto WP
![[js] basic syntax - for loop](/img/7f/6ddc47c062caa7d39538f88e12b1a0.jpg)
[js] basic syntax - for loop

物联网应用技术专业是属于什么类

Data Lake (VII): Iceberg concept and review what is a data Lake

搭建一个仪式感点满的网站,并内网穿透发布到公网 2/2

那些考研后才知道的事

What about data leakage? " Watson k'7 moves to eliminate security threats
![Primary code audit [no dolls (modification)] assessment](/img/b8/82c32e95d1b72f75823ca91c97138e.jpg)
Primary code audit [no dolls (modification)] assessment

Liar report query collection network PHP source code

荐号 | 有趣的人都在看什么?
随机推荐
Simple PHP paging implementation
Liste des liens (simple)
How to divide a large 'tar' archive file into multiple files of a specific size
瑞能实业IPO被终止:年营收4.47亿 曾拟募资3.76亿
Routing in laravel framework
Etcd database source code analysis -- rawnode simple package
uplad_ Labs first three levels
治臻新能源冲刺科创板:年营收2.2亿 上汽创投是股东
Blue Bridge Cup study 2022.7.5 (morning)
Zhubo Huangyu: it's really bad not to understand these gold frying skills
LeetCode_2(两数相加)
[machine learning notes] several methods of splitting data into training sets and test sets
Laravel generate entity
Zhubo Huangyu: these spot gold investment skills are not really bad
Comparison of several distributed databases
Laravel framework operation error: no application encryption key has been specified
Request + BS4 crawl Netease cloud music popular comments
Redis6 data type and operation summary
基于微信小程序的订餐系统
Jetpack compose introduction to mastery