二、搜索引擎篇-搭建es环境

一、添加es用户:

[root@javaxiaobang ~]# useradd es
[root@javaxiaobang ~]# passwd es

二、修改centos配置:

1、
[root@javaxiaobang ~]# vim /etc/sysctl.conf
#在文件最后面添加内容:
vm.max_map_count=262144
[root@javaxiaobang ~]# sysctl -p
2、
[root@javaxiaobang ~]# vim /etc/security/limits.conf
#修改文件内容:
* soft nproc 1000000
* hard nproc 1000000
* soft nofile 1000000
* hard nofile 1000000
3、
[root@javaxiaobang ~]# vim /etc/security/limits.d/90-nproc.conf
#修改文件内容:
* soft nproc 4096
4、切换到es用户
[root@javaxiaobang ~]# su es

三、安装JDK:

es不支持root用户启动

[es@javaxiaobang ~]$ 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

[es@javaxiaobang ~]$ 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






 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值