二、搜索引擎篇-搭建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






 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章