ElasticSearch03_Mapping字段映射、常用类型、数据迁移、ik分词器、自定义分词器(八)

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
Elasticsearch Serverless通用抵扣包,测试体验金 200元
简介: ElasticSearch03_Mapping字段映射、常用类型、数据迁移、ik分词器、自定义分词器(八)

④. ik_smart:会做最粗粒度的拆分,比如会将“中华人民共和国人民大会堂”拆分为中华人民共和国、人民大会堂。(前台搜索的时候用 ik_smart)


GET _analyze
{
   "analyzer": "ik_smart", 
   "text":"中华人民共和国人民大会堂"
}
{
  "tokens" : [
    {
      "token" : "中华人民共和国",
      "start_offset" : 0,
      "end_offset" : 7,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "人民大会堂",
      "start_offset" : 7,
      "end_offset" : 12,
      "type" : "CN_WORD",
      "position" : 1
    }
  ]
}


⑥. 自定义分词器


  • ①. 修改/usr/share/elasticsearch/plugins/ik/config中的IKAnalyzer.cfg.xml


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
  <comment>IK Analyzer 扩展配置</comment>
  <!--用户可以在这里配置自己的扩展字典 -->
  <entry key="ext_dict"></entry>
   <!--用户可以在这里配置自己的扩展停止词字典-->
  <entry key="ext_stopwords"></entry>
  <!--用户可以在这里配置远程扩展字典 -->
  <entry key="remote_ext_dict">http://192.168.56.10/es/fenci.txt</entry> 
  <!--用户可以在这里配置远程扩展停止词字典-->
  <!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>


②. 修改完成后,需要重启elasticsearch容器,否则修改不生效。docker restart elasticsearch


GET _analyze
{
   "analyzer": "ik_smart", 
   "text":"唐智谷粒商城"
}
{
  "tokens" : [
    {
      "token" : "唐智谷粒商城",
      "start_offset" : 0,
      "end_offset" : 6,
      "type" : "CN_WORD",
      "position" : 0
    }
  ]
}


③. 具体的操作步骤


[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS              PORTS                                                                                  NAMES
95de12634192   elasticsearch:7.4.2   "/usr/local/bin/dock…"   4 seconds ago   Up 3 seconds        0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 0.0.0.0:9300->9300/tcp, :::9300->9300/tcp   elasticsearch
a197c1d2cf05   kibana:7.4.2          "/usr/local/bin/dumb…"   30 hours ago    Up About a minute   0.0.0.0:5601->5601/tcp, :::5601->5601/tcp                                              kibana
a18680bef63e   redis                 "docker-entrypoint.s…"   5 weeks ago     Up 2 minutes        0.0.0.0:6379->6379/tcp, :::6379->6379/tcp                                              redis
91e02812975d   mysql:5.7             "docker-entrypoint.s…"   5 weeks ago     Up 2 minutes        0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                                   mysql
[root@localhost ~]# cd /mydata/
[root@localhost mydata]# ls
elasticsearch  mysql  redis
[root@localhost mydata]# mkdir nginx
[root@localhost mydata]# docker images
REPOSITORY      TAG       IMAGE ID       CREATED         SIZE
redis           latest    08502081bff6   8 weeks ago     105MB
mysql           5.7       09361feeb475   2 months ago    447MB
kibana          7.4.2     230d3ded1abc   22 months ago   1.1GB
elasticsearch   7.4.2     b1179d41a7b4   22 months ago   855MB
[root@localhost mydata]# docker run -p80:80 --name nginx -d nginx:1.10
Unable to find image 'nginx:1.10' locally
1.10: Pulling from library/nginx
6d827a3ef358: Pull complete 
1e3e18a64ea9: Pull complete 
556c62bb43ac: Pull complete 
Digest: sha256:6202beb06ea61f44179e02ca965e8e13b961d12640101fca213efbfd145d7575
Status: Downloaded newer image for nginx:1.10
24c1454acf9f8419f762f3369b59557df57cd6209864ef64000f2f26d9f0d05b
[root@localhost mydata]# mkdir -p /mydata/nginx/html
[root@localhost mydata]# mkdir -p /mydata/nginx/logs
[root@localhost mydata]# mkdir -p /mydata/nginx/conf
[root@localhost mydata]# ls
elasticsearch  mysql  nginx  redis
[root@localhost mydata]# cd nginx/
[root@localhost nginx]# ls
conf  html  logs
[root@localhost nginx]# cd ..
[root@localhost mydata]# rm -rf nginx/
[root@localhost mydata]# docker container cp nginx:/etc/nginx .
[root@localhost mydata]# ls
elasticsearch  mysql  nginx  redis
[root@localhost mydata]# docker stop nginx
nginx
[root@localhost mydata]# docker rm nginx 
nginx
[root@localhost mydata]# ls
elasticsearch  mysql  nginx  redis
[root@localhost mydata]# cd nginx
[root@localhost nginx]# ls
conf.d  fastcgi_params  koi-utf  koi-win  mime.types  modules  nginx.conf  scgi_params  uwsgi_params  win-utf
[root@localhost nginx]# cd ..
[root@localhost mydata]# mv nginx conf
[root@localhost mydata]# ls
conf  elasticsearch  mysql  redis
[root@localhost mydata]# mkdir nginx
[root@localhost mydata]# mv conf nginx/
[root@localhost mydata]# ls
elasticsearch  mysql  nginx  redis
[root@localhost mydata]# cd nginx/
[root@localhost nginx]# ls
conf
[root@localhost nginx]# docker run -p 80:80 --name nginx \
>  -v /mydata/nginx/html:/usr/share/nginx/html \
>  -v /mydata/nginx/logs:/var/log/nginx \
>  -v /mydata/nginx/conf/:/etc/nginx \
>  -d nginx:1.10
01bfbb6a8cd0e3f6af476793ad33fdc696740eadb125f8adad573303524adb55
[root@localhost nginx]# ls
conf  html  logs
[root@localhost nginx]# docker update nginx --restart=always
nginx
[root@localhost nginx]# echo '<h2>hello nginx!</h2>' >index.html
[root@localhost nginx]# ls
conf  html  index.html  logs
[root@localhost nginx]# rm -rf index.html 
[root@localhost nginx]# cd html
[root@localhost html]# echo '<h2>hello nginx!</h2>' >index.html
[root@localhost html]# 
[root@localhost html]# mkdir es
[root@localhost html]# cd es
[root@localhost es]# vi fenci.text
[root@localhost es]# ls
fenci.text
[root@localhost es]# mv fenci.text fenci.txt
[root@localhost es]# cd /mydata/
[root@localhost mydata]# cd elasticsearch/
[root@localhost elasticsearch]# ls
config  data  plugins
[root@localhost elasticsearch]# cd plugins/
[root@localhost plugins]# ls
ik
[root@localhost plugins]# cd ik/
[root@localhost ik]# ls
commons-codec-1.9.jar    config                               httpclient-4.5.2.jar  plugin-descriptor.properties
commons-logging-1.2.jar  elasticsearch-analysis-ik-7.4.2.jar  httpcore-4.4.4.jar    plugin-security.policy
[root@localhost ik]# cd config/
[root@localhost config]# ls
extra_main.dic         extra_single_word_full.dic      extra_stopword.dic  main.dic         quantifier.dic  suffix.dic
extra_single_word.dic  extra_single_word_low_freq.dic  IKAnalyzer.cfg.xml  preposition.dic  stopword.dic    surname.dic
[root@localhost config]# vi IKAnalyzer.cfg.xml 
[root@localhost config]# docker restart elasticsearch 
elasticsearch
[root@localhost config]# cd /mydata/nginx/
[root@localhost nginx]# ls
conf  html  logs
[root@localhost nginx]# cd html/es/
[root@localhost es]# ls
fenci.txt
[root@localhost es]# cat fenci.txt 
唐智谷粒商城
相关实践学习
以电商场景为例搭建AI语义搜索应用
本实验旨在通过阿里云Elasticsearch结合阿里云搜索开发工作台AI模型服务,构建一个高效、精准的语义搜索系统,模拟电商场景,深入理解AI搜索技术原理并掌握其实现过程。
ElasticSearch 最新快速入门教程
本课程由千锋教育提供。全文搜索的需求非常大。而开源的解决办法Elasricsearch(Elastic)就是一个非常好的工具。目前是全文搜索引擎的首选。本系列教程由浅入深讲解了在CentOS7系统下如何搭建ElasticSearch,如何使用Kibana实现各种方式的搜索并详细分析了搜索的原理,最后讲解了在Java应用中如何集成ElasticSearch并实现搜索。 &nbsp;
相关文章
|
存储 自然语言处理 数据库
使用Elasticsearch映射定义索引结构
使用Elasticsearch映射定义索引结构
219 0
|
自然语言处理 大数据 应用服务中间件
大数据-172 Elasticsearch 索引操作 与 IK 分词器 自定义停用词 Nginx 服务
大数据-172 Elasticsearch 索引操作 与 IK 分词器 自定义停用词 Nginx 服务
251 5
|
自然语言处理 关系型数据库 数据库
ElasticSearch 映射类型及数据类型区分
ElasticSearch 映射类型及数据类型区分
191 0
|
自然语言处理 应用服务中间件 nginx
一文教会你 分词器elasticsearch-analysis-ik 的安装使用【自定义分词库】
这篇文章是关于如何在Elasticsearch中安装和使用ik分词器的详细教程,包括版本匹配、安装步骤、分词测试、自定义词库配置以及创建使用ik分词器的索引的方法。
一文教会你 分词器elasticsearch-analysis-ik 的安装使用【自定义分词库】
|
存储 自然语言处理 关系型数据库
ElasticSearch基础3——聚合、补全、集群。黑马旅游检索高亮+自定义分词器+自动补全+前后端消息同步
聚合、补全、RabbitMQ消息同步、集群、脑裂问题、集群分布式存储、黑马旅游实现过滤和搜索补全功能
ElasticSearch基础3——聚合、补全、集群。黑马旅游检索高亮+自定义分词器+自动补全+前后端消息同步
|
自然语言处理 搜索推荐
在Elasticsearch 7.9.2中安装IK分词器并进行自定义词典配置
在Elasticsearch 7.9.2中安装IK分词器并进行自定义词典配置
1487 1
Elasticsearch自定义时间格式
Elasticsearch自定义时间格式
317 0
|
SQL 安全 数据挖掘
Elasticsearch如何聚合查询多个统计值,如何嵌套聚合?并相互引用,统计索引中某一个字段的空值率?语法是怎么样的?
Elasticsearch聚合查询用于复杂数据分析,包括统计空值率。示例展示了如何计算字段`my_field`非空非零文档的百分比。查询分为三步:总文档数计数、符合条件文档数计数及计算百分比。聚合概念涵盖度量、桶和管道聚合。脚本在聚合中用于动态计算。常见聚合类型如`sum`、`avg`、`date_histogram`等。组合使用可实现多值统计、嵌套聚合和空值率计算。[阅读更多](https://zhangfeidezhu.com/?p=515)
514 0
Elasticsearch如何聚合查询多个统计值,如何嵌套聚合?并相互引用,统计索引中某一个字段的空值率?语法是怎么样的?
|
自然语言处理 数据可视化 Linux
ElasticSearch安装ik分词器_使用_自定义词典
ElasticSearch安装ik分词器_使用_自定义词典
254 1
|
数据安全/隐私保护 网络架构 索引
Elasticsearch索引数据的路由规则与自定义路由分发
Elasticsearch索引数据的路由规则与自定义路由分发
328 0

热门文章

最新文章