ElasticSearch配置

ElasticSearch配置

概念

  • 節(jié)點 (node), 集群 (cluster)
    單臺服務(wù)器,存儲數(shù)據(jù)并參與集群的索引和搜索,服務(wù)器在啟動時自動分配ID ,節(jié)點默認會加入IDElasticSearch的集群中,除非自己配置,如果只有一個節(jié)點,那么該節(jié)點也作為一個集群工作。
    多個節(jié)點組成的一個集群,集群可跨節(jié)點,進行聯(lián)合索引和搜索。集群默認IDElasticSearch

  • 索引(index) ,類型(type) ,文檔(document)
    例:
    index可為blogSystem;
    type可為blogs,comments,user;
    document存儲基本信息元;

  • 分片 (shard)副本(replica)
    可為一個索引指定n個分片,分片可以存儲在集群中任一個節(jié)點上。
    一個索引默認分配5個分片和一個副本

安裝運行

//普通用戶身份操作(解壓)curl -L -O 
https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.0.0/elasticsearch-2.0.0.tar.gz
...
...
tar -xvf elasticsearch-2.0.0.tar.gzcd elasticsearch-2.0.0/bin./elasticsearch
...
...

占用9200端口,對文檔操作提供REST API

curl -X<REST Verb> <Node>:<Port>/<Index>/<Type>/<ID>
//exp
curl -XGET 'localhost:9200/index/type/id?pretty'
curl -XPUT 'localhost:9200/index/type/1' -d '{ "name": "John Doe"}'
curl -XDELETE 'localhost:9200/customer'

CRUD語法- 查詢

curl -XPOST 'localhost:9200/bank/_search?pretty' -d '{ "query": { "match-all": { } }, //所有文檔 
"query": { "match": { "address": "mill" } }, //特定文檔
"query": { "match": { "address": "aaa bbb" } }, //含有aaa或bbb "query": { "match_phrase": { "address": "aaa bbb" } }, //含有"aaa bbb"
"size":10, //記錄條數(shù) 
"from":10, //記錄跳頁
"sort": { "balance": { "order": "desc" } },//排序
//與 
"query": { 
  "bool": {  
   "must": [ { "match": { "address": "mill" } },
             { "match": { "address": "lane" } } 
    ]
  } 
}, 
//或 
"query": { 
  "bool": { 
    "should": [ 
      { "match": { "address": "mill" } }, 
      { "match": { "address": "lane" } }
     ]
   }
 },
 //非 
"query": { 
  "bool": {
     "must_not": [
       { "match": { "address": "mill" } },
       { "match": { "address": "lane" } }
       ]
     }
 }, 
//多條件 
"query": { 
  "bool": {
     "must": [
       { "match": { "age": "40" } } ],
     "must_not": [ 
        { "match": { "state": "ID" } }
       ]
   }
  },
 //范圍選擇 
"query": {  
  "bool": { 
     "must": { "match_all": {} },
     "filter": {  
        "range": { 
          "balance": {"gte": 20000,"lte": 30000} 
        }
     }
   } 
}, 
 //排序 
"aggs": { 
  "group_by_state": {
       "terms": { "field": "state" } 
    }
   } 
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容