二、搜索引擎篇-搭建es环境
程序员文章站
2022-04-29 08:09:56
...
一、添加es用户:
[aaa@qq.com ~]# useradd es
[aaa@qq.com ~]# passwd es
二、修改centos配置:
1、
[aaa@qq.com ~]# vim /etc/sysctl.conf
#在文件最后面添加内容:
vm.max_map_count=262144
[aaa@qq.com ~]# sysctl -p
2、
[aaa@qq.com ~]# vim /etc/security/limits.conf
#修改文件内容:
* soft nproc 1000000
* hard nproc 1000000
* soft nofile 1000000
* hard nofile 1000000
3、
[aaa@qq.com ~]# vim /etc/security/limits.d/90-nproc.conf
#修改文件内容:
* soft nproc 4096
4、切换到es用户
[aaa@qq.com ~]# su es
三、安装JDK:
es不支持root用户启动
[aaa@qq.com ~]$ vim ~/.bash_profile
#配置环境变量
export JAVA_HOME=/usr/java/default
export MAVEN_HOME=/root/javaxiaobang/apache-maven-3.6.1
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export PATH=${MAVEN_HOME}/bin:${JAVA_HOME}/bin:/usr/local/nginx/sbin:/usr/local/mysql/bin:${JRE_HOME}/bin:$PATH
export PATH
[aaa@qq.com ~]$ source ~/.bash_profile
四、安装es:
es不支持root用户启动
1、修改config/elasticsearch.yml文件
修改内容:
cluster.name: es
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
2、启动es
nohup elasticsearch-6.5.3/bin/elasticsearch > es.log &
3、访问es:
五、安装kibana:
1、修改config/kibana.yml文件:
server.port: 5601
server.host: "0.0.0.0"
elasticsearch.url: "http://127.0.0.1:9200"
kibana.index: ".kibana"
2、启动kibana:
nohup kibana-6.5.3-linux-x86_64/bin/kibana > kibana.log &
3、访问kibana:
六、通过kibana操作es:
DevTools下操作:
#创建索引
PUT /index_1
#创建索引类别
PUT /index_1/_mappings/songs
{
"properties": {
"songName" : {"type": "text"},
"singer" : {"type": "text"},
"lyrics" : {"type": "text"}
}
}
#填充索引数据
POST /index_1/songs
{
"songName" : "take me to your heart",
"singer" : "Michael Learns To Rock",
"lyrics" : "Hiding from the rain and snow,Trying to forget but I won’t let go,Looking at a crowded street,Listening to my own heart beat,So many people all around the world,Tell me where do I find someone like you girl,Take me to your heart take me to your soul,Give me your hand before I’m old,Show me what love is - haven’t got a clue,Show me that wonders can be true,They say nothing lasts forever,We’re only here today,Love is now or never,Bring me far away,Take me to your heart take me to your soul,Give me your hand and hold me,Show me what love is - be my guiding star,It’s easy take me to your heart,Standing on a mountain high,Looking at the moon through a clear blue sky,I should go and see some friends,But they don’t really comprehend,Don’t need too much talking without saying anything,All I need is someone who makes me wanna sing,Take me to your heart take me to your soul,Give me your hand before I’m old,Show me what love is - haven’t got a clue,Show me that wonders can be true,They say nothing lasts forever,We’re only here today,Love is now or never,Bring me far away,Take me to your heart take me to your soul,Give me your hand and hold me,Show me what love is - be my guiding star,It’s easy take me to your heart,Take me to your heart take me to your soul,Give me your hand and hold me,Show me what love isbe my guiding star,It’s easy take me to your heart"
}
#填充索引数据
POST /index_1/songs
{
"songName" : "you are beautiful",
"singer" : "James Blunt",
"lyrics" : "My life is brilliant,My life is brilliant,My love is pure,I saw an angel.Of that I‘m sure. ,She smiled at me on the subway. ,She was with another man. ,But I won‘t lose no sleep on that,Cause I‘ve got a plan,You‘re beautiful. You‘re beautiful,You‘re beautiful, it‘s true,I saw your face in a crowded place,And I don‘t know what to do,Cause I‘ll never be with you,Yeah, she caught my eye,As we walked on by,She could see from my face that I was,Fucking high,And I don‘t think that I‘ll see her again,But we shared a moment that will last till the end,You‘re beautiful. You‘re beautiful,You‘re beautiful, it‘s true,I saw your face in a crowded place ,And I don‘t know what to do,‘Cause I‘ll never be with you,La la la la, la la la la, la la la la ,laaaaaa,You‘re beautiful. You‘re beautiful,You‘re beautiful, it‘s true,There must be an angel with a smile on her face ,When she thought up that I should be with you,But it‘s time to face the truth,I will never be with you"
}
#查询索引数据
GET /index_1/_search
#按照歌名搜索
GET /index_1/_search?q=songName:"beautiful"
#按照歌手搜索
GET /index_1/_search?q=singer:"Rock"
#按照歌词搜索
GET /index_1/_search?q=lyrics:"la la la la"
#指定索引别名
PUT /index_1/_alias/music
#通过索引别名去查询
GET /music/_search?q=songName:"beautiful"
#创建新的索引
PUT /index_2
#索引文档
PUT /index_2/songs/5
{
"songName" : "could this be love",
"singer" : "Jennifer Lopez",
"lyrics" : "Could This Be love,Woke Up This Morning Just Sat In My Bed,8 a.m. First Thing In My Head,Is A Certain Someone Who's Always On My Mind,He Treats Me Like A Lady In Every Way,He Smiles And Warms Me Through Up The Day,Should I Tell Him I Love You Wish I Knew What To Say,Could This Be Love That I Feel,So Strong So Deep And So Real,If I Lost You Would I Ever Heal,Could This Be Love That I Feel,Could This Be "
}
#切换索引别名
POST /_aliases
{
"actions": [
{
"add": {
"index": "index_2",
"alias": "music"
}
},{
"remove": {
"index": "index_1",
"alias": "music"
}
}
]
}
#过滤条件
POST _aliases
{
"actions": [
{
"add": {
"index": "index_1",
"alias": "music_filter",
"filter": {
"match":{
"singer":"Rock"
}
}
}
}
]
}
GET /music_filter/_search
GET /music/_search
GET /index_1/_search
#从DB同步数据到ES
推荐阅读
-
Hexo+Github博客搭建之环境准备篇
-
Hexo+Github博客搭建之环境搭建篇
-
Android NDK 环境搭建 之 起始篇NDK HelloWorld
-
C 编程环境搭建 Window 篇
-
Eclipse和PyDev搭建完美Python开发环境教程(Windows篇)
-
C 编程环境搭建 Window 篇
-
CentOS7 LNMP+phpmyadmin环境搭建 第三篇phpmyadmin安装
-
CentOS7 LNMP+phpmyadmin环境搭建 第一篇虚拟机及centos7安装
-
CentOS7 LNMP+phpmyadmin环境搭建 第二篇LNMP环境搭建教程
-
[Revit]Autodesk Revit 二次开发整理(资料、准备工作和环境搭建)