惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
T
The Blog of Author Tim Ferriss
博客园 - 叶小钗
N
Netflix TechBlog - Medium
腾讯CDC
C
Check Point Blog
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
S
SegmentFault 最新的问题
F
Fortinet All Blogs
美团技术团队
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
F
Full Disclosure
Recorded Future
Recorded Future
D
DataBreaches.Net
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
J
Java Code Geeks
I
InfoQ
Y
Y Combinator Blog
A
About on SuperTechFans
AI
AI
爱范儿
爱范儿
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Forbes - Security
Forbes - Security
W
WeLiveSecurity
M
MIT News - Artificial intelligence
雷峰网
雷峰网
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Simon Willison's Weblog
Simon Willison's Weblog
Schneier on Security
Schneier on Security
The GitHub Blog
The GitHub Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
Latest news
Latest news
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Docker
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
V2EX - 技术
V2EX - 技术
Project Zero
Project Zero

博客园 - 猫猫客服

Goframe 学习笔记 cursor编辑器 ai客服 laravel12 微服务 Claude Code 接口类,需要指定入参类型,出参类型 海量数据查询,es替代方案 数据库设计 php消费者 转载,电商系统多规格 php响应 docker,2024年8月9日 使用wsl,windows自带的linux虚拟机 go 微服务 vue3 前端工具 java基础 架构 简单分表 go 指针
es学习
猫猫客服 · 2024-07-24 · via 博客园 - 猫猫客服

msql     对应       es

表      -----------  索引index

行      -----------  文档Document

列      -----------   字段field

表结构 ----------- 映射mapping

sql语句-----------dsl语句

kibana 类似 mysql连接工具客户端

建议用的版本跟我一样,8比较麻烦

docker run -d --name es7 -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" -e "discovery.type=single-node" --privileged -p 9200:9200 -p 9300:9300 --restart=always elasticsearch:7.12.1

需要挂载文件夹,不然后面很麻烦

 这种-v写法比较好,不用创建文件夹,就不会清空原来有的文件,可以在/var/lib/docker/volumes找到对的文件夹

具体会不会清空,需要测试一下才知道。(经测试:这样写不会清空原有的文件,推荐这样写)

9200端口:给php连接用的

 9300端口:es互联使用,一台es没用 

安装后访问 ip:9200 正常表示成功 

 docker run -d --name kibana7 -e ELASTICSEARCH_HOSTS=http://192.168.12.135:9200 -p 5601:5601 kibana:7.12.1

注意:这里使用ip

默认bridge网络中所有容器间只能用IP相互访问。自定义bridge网络中所有容器除ip访问外,还可以直接用容器名作为hostname相互访问。

分词:需要安装分词器,不然默认的分词器会一个个字分开

在github搜索后下载对应版本

 /usr/share/elasticsearch/plugins

文件夹必须叫ik,先改名后复制进去

重启即可使用

分词器拓展

在ik文件夹(挂载出来,不然修改麻烦)

常用mapping类型(类似mysql的表字段类型)

字符串:细分text(支持分词) 或 keyword(不分词)

数值类型:long、integer、short、byte、double、float

布尔:boolean

日期:date

对象:object

每个字段都可以设置是否建立字段索引,建立字段索引才会被搜索出来,默认true

analyzer:使用哪种分词器(text类型才能选择)

properties:字段的子字段

例子:

 es不可以修改索引库(表)

注意:可以新增字段

可以先删除,再新增 代替修改

全量修改:不存在则新增

注意 id 不是用long,用keyword

{ "mappings": { "_doc": { "properties": { "all": { "type": "text", "analyzer": "ik_max_word" }, "create_at": { "type": "keyword" }, "email": { "type": "keyword", "index": false }, "id": { "type": "keyword" }, "info": { "type": "text", "copy_to": [ "all" ], "analyzer": "ik_max_word" }, "user_name": { "type": "text", "copy_to": [ "all" ], "analyzer": "ik_smart" } } } } }

composer require elasticsearch/elasticsearch:7.12.0

 1 <?php
 2 namespace app\api\controller;
 3 
 4 use Elasticsearch\Client;
 5 use Elasticsearch\ClientBuilder;
 6 
 7 class Es
 8 {
 9     private static ?Client $client = null;
10 
11     //连接
12     public static function getClient(): ?Client
13     {
14         if (self::$client === null) {
15             // 一个或多个Elasticsearch节点的URL
16             $hosts = ['http://192.168.12.135:9200'];
17             self::$client = ClientBuilder::create()->setHosts($hosts)->build();
18         }
19 
20         return self::$client;
21     }
22 
23     // 插入
24     // 插入数据的方法
25     public function insertData()
26     {
27         $params = [
28             'index' => 'tp5-user',
29             'id' => 3,
30             'body' => [
31                 'id' => 3,
32                 'user_name' => 'xiaohong',
33                 'info' => '白嫖gg',
34                 'email' => 'xiaohong@qq.com',
35                 'create_at' => '1721883969'
36             ]
37         ];
38 
39         try {
40             $response = self::getClient()->index($params);
41             echo "Document inserted successfully.\n";
42             print_r($response);
43         } catch (\Exception $e) {
44             echo "Error inserting document: " . $e->getMessage();
45         }
46     }
47 
48     // 搜索
49     public function search()
50     {
51         $params = [
52             'index' => 'tp5-user',
53             'body'  => [
54                 'query' => [
55                     'match' => [
56                         'all' => 'tom'
57                     ]
58                 ]
59             ]
60         ];
61 
62         $results = self::getClient()->search($params);
63 
64         dump($results);
65     }
66 }