1. 程式人生 > 實用技巧 >ElasticSearch學習筆記_2

ElasticSearch學習筆記_2

首先記錄一個學習es的時候遇到的一個坑,錯誤是

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

網上的解答都是修改

etc/security/limits.conf

sudo vi /etc/security/limits.conf
在檔案最後面加上

soft nofile 65536
hard nofile 65536
soft nproc 4096
hard nproc 4096
注:*後面有空格

可是修改後,發現root使用者的值變大了,可是普通使用者還是4096,那還是不能執行es啊,網上基本沒有說如何讓普通使用者的值發生變化,卡了我很長時間,直到我在知乎上看到下面的內容,

才清楚原來我是本地部署還要有普通使用者許可權才行,哎,怪自己linux學的不好,只要su + 普通使用者的名字就可以讓普通使用者有管理員許可權,之後就可成功執行es.

在網上看到了一個博主寫的關於es的安裝和相關軟體的安裝的教程,比如安裝node.js,ik分詞器,視覺化工具head。和kibana,轉載一下。

https://www.cnblogs.com/yijialong/p/9717593.html

#萬用字元查詢?用來匹配一個任意的字元*用來匹配多個字元
GET /ems/_search
{
  "query": {
    "wildcard": {
      "content": {
        
"value": "sp*" } } } } GET /ems/_search { "query": { "wildcard": { "content": { "value": "框*" } } } } #多id進行查詢,不過一般不會宣告id GET ems/_search { "query": { "ids": { "values": [ "AoUFPHUBwStJbspbRiwc","A4UFPHUBwStJbspbRiwc"] } } } #模糊查詢。此時當查詢的內容與被查詢的內容之間的編輯距離不大於2時可以成功的進行模糊匹配,具體是2個字元一下的要完全正確,2到4個只能錯1個,五個以上最多錯2個,其中編輯距離的概念是是指兩個字串之間,由一個轉成另一個(增刪改)所需的最少編輯操作次數 GET
/ems/_search { "query": { "fuzzy": { "content": "架構" } } } #布林查詢,是對多個條件實現複雜查詢,bool表示式 #must 相當於&&同時成立,should: 相當於||成立一個就可以 #must not: 相當於!不能滿足任何一個 GET /ems/_search { "query": { "bool": { "must": [ {"term": { "content": "語" }} ] , "must_not": [ {"term": { "age": { "value": "43" } }} ] } } } #多欄位查詢。得分是根據文章長度,和匹配到的次數,文章越短匹配次數越多越正確 #對於欄位來說型別是text的需要對query進行分詞處理,對於address則需要整體進行匹配 GET /ems/_search { "query": { "multi_match": { "query": "上海框架", "fields": ["content","address"] } } } #多欄位分詞查詢,這種查詢方式需要先設定好分詞器的型別 GET /ems/_search { "query": { "multi_match": { "analyzer": "simple", "query": "架構", "fields": ["content","address"] } } } GET _analyze#分成的結果是一個字或一個詞 { "analyzer": "standard", "text": "spring is a " } GET _analyze#做最細粒度分詞 { "analyzer": "ik_max_word", "text": "五常大米" } GET _analyze#做粗粒度分詞 { "analyzer": "ik_max_word", "text": "五常大米" } GET _analyze#分成的結果是個整體,對中文不分詞,對英文分成單詞,去掉數字 { "analyzer": "simple", "text": "這是個框架" } #高亮查詢,一般把型別設定為text方便進行匹配 GET /ems/_search { "query": {"term": { "content": { "value": "開" } }}, "highlight": { "fields": {"*": {}}, "pre_tags": ["<span style='color:red'>"], "post_tags": ["</span>"], "require_field_match": "false" } } PUT /log #給資料庫提前宣告使用的分詞器是ik { "mappings": { "properties": { "id":{ "type": "integer" }, "ip":{ "type": "text" , "analyzer": "ik_max_word" }, "content":{ "type": "text" , "analyzer": "ik_max_word" } } } } PUT /log/_doc/_bulk {"index":{}} {"id":12,"ip":"1.1.1.1","content":"我想看劉德華演的電視劇"} GET /log/_search { "query": { "term": { "content": { "value": "電視劇" } } } } GET _analyze#碰瓷被拆開了,要引入擴充套件詞。包括靜態擴充套件和動態擴充套件 { "analyzer": "ik_max_word", "text": "打擊估計碰瓷的違法犯罪人員" } GET _analyze#碰瓷被拆開了,要引入擴充套件詞。包括靜態擴充套件和動態擴充套件 { "analyzer": "ik_max_word", "text": "no space in the queue" } GET _analyze#去停用詞,同樣在ik的yml檔案裡面進行配置,這次把百里守約當做停用詞,百里守約被去除 { "analyzer": "ik_max_word", "text": "hello world 好學生,真的很優秀" } #更多的是使用遠端擴充套件詞典和去停用詞,動態進行更新,不需要每次都啟動es,但是需要開啟一個服務,如Tomcat、具體操作可以百度,就是在配置檔案裡面加一個URL DELETE b_log PUT /b_log { "mappings": { "properties": { "id":{ "type": "integer" }, "log_id":{ "type":"keyword" }, "ip":{ "type": "ip" }, "sysname":{ "type": "keyword" }, "modulename":{ "type": "text" }, "level":{ "type": "keyword" }, "logtime":{ "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" }, "createtime":{ "type": "date", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" }, "content":{ "analyzer": "ik_max_word", "type": "text" } } } } PUT /b_log/_bulk {"index":{}} {"id":16,"ip":"1.1.1.1","sysname":"abc","modulename":"module1","level":"1","logtime":"2019-10-10 10:10:10","createtime":"2019-10-10 10:10:10","content":"我想看劉德華演的電視劇"} {"index":{}} {"id":17,"ip":"1.1.1.1","sysname":"abc","modulename":"module2","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content":"this is a test."} {"index":{}} {"id":18,"ip":"1.1.1.1","sysname":"abc","modulename":"module3","level":"1","logtime":"2019-10-10 10:10:10","createtime":"2019-10-10 10:10:10","content":"no space in the queue"} {"index":{}} {"id":19,"ip":"1.1.1.1","sysname":"abc","modulename":"module1","level":"1","logtime":"2018-10-10 10:10:10","createtime":"2018-10-10 10:10:10","content":"linkindex=0,connindex=0,Proto_Connect: socket connect failed. HostName=127.0.0.1, port=10004,socketid=1964"} {"index":{}} {"id":20,"ip":"1.1.1.1","sysname":"abc","modulename":"module1","level":"1","logtime":"2018-10-10 10:10:10","createtime":"2018-10-10 10:10:10","content":"linkindex=0,connindex=0,Proto_Connect: socket connect failed. HostName=127.0.0.1, port=10004,socketid=1964"} {"index":{}} {"id":21,"ip":"1.1.1.1","sysname":"abc","modulename":"module1","level":"1","logtime":"2018-10-10 10:10:10","createtime":"2018-10-10 10:10:10","content":"linkindex=0,connindex=0,Proto_Connect: socket connect failed. HostName=127.0.0.1, port=10004,socketid=1964"} {"index":{}} {"id":22,"ip":"10.3.8.211","sysname":"sys1","modulename":"child.c","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content":"[2836] ThreadID[0] SocketCount[0] Status[2]"} {"index":{}} {"id":23,"ip":"10.3.8.211","sysname":"sys1","modulename":"child.c","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content":"[2836] ThreadID[0] SocketCount[0] Status[2]"} {"index":{}} {"id":24,"ip":"10.3.8.211","sysname":"sys1","modulename":"child.c","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content":"[2836] ThreadID[0] SocketCount[0] Status[2]"} {"index":{}} {"id":25,"ip":"10.3.8.211","sysname":"sys1","modulename":"child.c","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content":"[2836] ThreadID[0] SocketCount[0] Status[2]"} {"index":{}} {"id":26,"ip":"10.3.8.211","sysname":"sys1","modulename":"child.c","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content":"[2836] ThreadID[0] SocketCount[0] Status[2]"} {"index":{}} {"id":22,"ip":"10.3.8.211","sysname":"sys1","modulename":"child.c","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content":"[2836] ThreadID[0] SocketCount[0] Status[2]"} {"index":{}} {"id":22,"ip":"10.3.8.211","sysname":"sys1","modulename":"child.c","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content":"[2836] ThreadID[0] SocketCount[0] Status[2]"} {"index":{}} {"id":22,"ip":"10.3.8.211","sysname":"sys1","modulename":"child.c","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content": "[2836] ThreadID[0] SocketCount[0] Status[2]"} {"index":{}} {"id":22,"ip":"10.3.8.211","sysname":"sys1","modulename":"child.c","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content":"[2836] ThreadID[0] SocketCount[0] Status[2]"} {"index":{}} {"id":22,"ip":"10.3.8.211","sysname":"sys1","modulename":"child.c","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content":"[2836] ThreadID[0] SocketCount[0] Status[2]"} {"index":{}} {"id":22,"ip":"10.3.8.211","sysname":"sys1","modulename":"child.c","level":"2","logtime":"2020-10-10 10:10:10","createtime":"2020-10-10 10:10:10","content":"[2836] ThreadID[0] SocketCount[0] Status[2]"} {"index":{}} {"id": 10009, "ip": "127.0.0.1", "sysname": "systest", "modulename": "MsgLocQue.c", "level": "4", "logtime": "2020-10-16 12:45:12", "createtime": "2020-11-03 17:59:57", "content": "MoniLocMsgDes:msg[54] msgid=[ID:d6a9581f800035f89216f29800000] que[lq] Expire is over,will delete msg}\x"} GET /b_log/_search { "query": { "term": { "content": "電視劇" } } } GET /b_log/_search {"query": {"bool":{"must":[ {"match_phrase":{"content":"linkindex=0,connindex=0,Proto_Connect: socket connect failed. HostName=127.0.0.1, port=10004,socketid="}} ]}}} GET /b_log/_search { "query": { "bool": { "must": [ {"term": { "content": "語"}}, {"age": { "value": "43" }} ] } } } GET /b_log/_count { }