当前位置:网站首页>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
边栏推荐
- 基于微信小程序的订餐系统
- Rk3566 add LED
- ETCD数据库源码分析——集群间网络层客户端peerRt
- Require, require in PHP_ once、include、include_ Detailed explanation of the efficiency of repeated introduction of once class library
- Liar report query collection network PHP source code
- 嵌入式软件架构设计-消息交互
- Idea remote debugging agent
- Redis6 master-slave replication and clustering
- [machine learning notes] how to solve over fitting and under fitting
- Kafaka log collection
猜你喜欢
![[South China University of technology] information sharing of postgraduate entrance examination and re examination](/img/a8/41e62a7a8d0a2e901e06c751c30291.jpg)
[South China University of technology] information sharing of postgraduate entrance examination and re examination

国富氢能冲刺科创板:拟募资20亿 应收账款3.6亿超营收

神经网络物联网未来发展趋势怎么样

Liar report query collection network PHP source code

基于微信小程序的订餐系统

Jasypt configuration file encryption | quick start | actual combat

ZABBIX monitoring

Why do I support bat to dismantle "AI research institute"

那些考研后才知道的事

Attack and defense world web WP
随机推荐
Leetcode array question brushing notes
Recommendation number | what are interesting people looking at?
PHP generate Poster
网络安全-HSRP协议
神经网络物联网未来现状和趋势及看法
神经网络物联网未来发展趋势怎么样
How to divide a large 'tar' archive file into multiple files of a specific size
OSI and tcp/ip protocol cluster
aspx 简单的用户登录
JS takes key and value from an array object to form a new object
物联网应用技术专业是属于什么类
Getting started with rce
【华南理工大学】考研初试复试资料分享
Solve the problem of invalid uni app configuration page and tabbar
Routing in laravel framework
Network security - Novice introduction
Simple process of penetration test
2022年机修钳工(高级)考试题模拟考试题库模拟考试平台操作
Requests + BS4 crawl Douban top250 movie information
Internal JSON-RPC error. {"code":-32000, "message": "execution reverted"} solve the error