ElasticSearch是一個基於Lucene的搜索服務器。它提供了一個分佈式多用戶能力的全文搜索引擎,基於RESTful web接口。Elasticsearch是用Java開發的,並做爲Apache許可條款下的開放源碼發佈,是當前流行的企業級搜索引擎。html
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.0.tar.gz tar -xvzf elasticsearch-6.4.0.tar.gz cd elasticsearch-6.4.0/bin ./elasticsearch -d
# ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # cluster.name: my-application # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # network.host: 192.168.141.129 # # Set a custom port for HTTP: # http.port: 9200 # # For more information, consult the network module documentation. #
再次啓動報錯:node
[2018-09-13T09:29:43,060][INFO ][o.e.b.BootstrapChecks ] [7hyiUY2] bound or publishing to a non-loopback address, enforcing bootstrap checks ERROR: [2] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解決方案:web
vi /etc/security/limits.conf # 添加兩行行配置,並重連SSH elasticsearch soft nofile 65536 elasticsearch hard nofile 65537 vi /etc/sysctl.conf # 添加一行配置 vm.max_map_count=262144 sysctl -p
地址:
http://192.168.141.129:9200/?pretty
顯示:
正則表達式
http://www.javashuo.com/article/p-mfnljgnt-gp.html數據庫
GET /_cat | 命令解釋 |
---|---|
/_cluster/stats | 查看集羣統計信息 |
/_cat/allocation | |
/_cat/shards | |
/_cat/shards/{index} | |
/_cat/master | |
/_cat/nodes | 查看集羣的節點列表 |
/_cat/tasks | |
/_cat/indices | 查看全部索引 |
/_cat/indices/{index} | 查看指定索引 |
/_cat/segments | |
/_cat/segments/{index} | |
/_cat/count | |
/_cat/count/{index} | |
/_cat/recovery | |
/_cat/recovery/{index} | |
/_cat/health | 查看集羣的健康情況 |
/_cat/pending_tasks | |
/_cat/aliases | |
/_cat/aliases/{alias} | |
/_cat/thread_pool | |
/_cat/thread_pool/{thread_pools} | |
/_cat/plugins | |
/_cat/fielddata | |
/_cat/fielddata/{fields} | |
/_cat/nodeattrs | |
/_cat/repositories | |
/_cat/snapshots/{repository} | |
/_cat/templates | |
/_stats | 查看全部的索引狀態 |
直接建立json
PUT twitter
settingsbootstrap
PUT twitter { "settings" : { "index" : { "number_of_shards" : 3, "number_of_replicas" : 2 } } }
mappings數組
PUT twitter { "settings" : { "index" : { "number_of_shards" : 3, "number_of_replicas" : 2 } }, "mappings" : { "_doc" : { "properties" : { "field1" : { "type" : "text" } } } } }
GET /twitter/ GET /twitter/_search
DELETE /twitter
Core Datatypes 核心類型 string text and keyword Numeric datatypes long, integer, short, byte, double, float, half_float, scaled_float Date datatype date Boolean datatype boolean Binary datatype binary Range datatypes 範圍 integer_range, float_range, long_range, double_range, date_range Complex datatypes 複合類型 Array datatype 數組就是多值,不須要專門的類型 Object datatype object :表示值爲一個JSON 對象 Nested datatype nested:for arrays of JSON objects(表示值爲JSON對象數組 ) Geo datatypes 地理數據類型 Geo-point datatype geo_point: for lat/lon points (經緯座標點) Geo-Shape datatype geo_shape: for complex shapes like polygons (形狀表示) Specialised datatypes 特別的類型 IP datatype ip: for IPv4 and IPv6 addresses Completion datatype completion: to provide auto-complete suggestions Token count datatype token_count: to count the number of tokens in a string mapper-murmur3 murmur3: to compute hashes of values at index-time and store them in the index Percolator type Accepts queries from the query-dsl join datatype Defines parent/child relation for documents within the same index
指定id PUT twitter/_doc/1 { "id": 1, "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" } 自動生成id POST twitter/_doc/ { "id": 1, "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" }
HEAD twitter/_doc/11 GET twitter/_doc/1
PUT twitter/_doc/1 { "id": 1, "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" }
DELETE twitter/_doc/1
POST _bulk { "index" : { "_index" : "test", "_type" : "_doc", "_id" : "1" } } { "field1" : "value1" } { "delete" : { "_index" : "test", "_type" : "_doc", "_id" : "2" } } { "create" : { "_index" : "test", "_type" : "_doc", "_id" : "3" } } { "field1" : "value3" } { "update" : {"_id" : "1", "_type" : "_doc", "_index" : "test"} } { "doc" : {"field2" : "value2"} } index 不管是否存在,都會成功 create 存在會提示 update 不存在會提示 delete 不存在會提示
POST /my_store/_doc/_bulk { "index": { "_id": 1 }} { "price" : 10, "productID" : "XHDK-A-1293-#fJ3" } { "index": { "_id": 2 }} { "price" : 20, "productID" : "KDKE-B-9947-#kL5" } { "index": { "_id": 3 }} { "price" : 30, "productID" : "JODL-X-1937-#pV7" } { "index": { "_id": 4 }} { "price" : 30, "productID" : "QQPX-R-3956-#aD8" }
一個字段查詢服務器
GET my_store/_doc/_search { "query": { "term": { "price": "30" } } }
GET my_store/_doc/_search { "query": { "bool": { "should": [ { "term": { "price": 20 } }, { "term": { "productID": "XHDK-A-1293-#fJ3" } } ], "must_not": { "term": { "price": 30 } } } } } PUT my_store { "mappings" : { "_doc" : { "properties" : { "productID" : { "type" : "keyword" } } } } } GET /my_store/_analyze { "field": "productID", "text": "XHDK-A-1293-#fJ3" }
GET my_store/_doc/_search { "query": { "match": { "productID": "b" } }, "highlight": { "pre_tags" : ["<span class='hlt'>"], "post_tags" : ["</span>"], "title": {}, "content": {} } } }
POST /my_index/my_type/_bulk { "index": { "_id": 1 }} { "title": "The quick brown fox" } { "index": { "_id": 2 }} { "title": "The quick brown fox jumps over the lazy dog" } { "index": { "_id": 3 }} { "title": "The quick brown fox jumps over the quick dog" } { "index": { "_id": 4 }} { "title": "Brown fox brown dog" }
GET /my_index/my_type/_search { "query": { "match": { "title": "QUICK!" } } } GET /my_index/_analyze { "field": "title", "text": "QUICK!" }
GET /my_index/my_type/_search { "query": { "bool": { "must": { "match": { "title": "quick" }}, "must_not": { "match": { "title": "lazy" }}, "should": [ { "match": { "title": "brown" }}, { "match": { "title": "dog" }} ] } } }
POST _analyze { "tokenizer": "standard", "char_filter": [ "html_strip" ], "filter": [ "lowercase", "asciifolding" ], "text": "Is this déja vu?" } POST _analyze { "analyzer": "ik_smart", "text": "微知" }
示例架構
PUT customer { "mappings": { "_doc": { "properties": { "customerName": { "type": "text", "analyzer": "ik_smart", "search_analyzer": "ik_smart" }, "companyId": { "type": "text" } } } } } POST /customer/_doc/_bulk { "index": { "_id": 1 }} { "companyId": "55", "customerName": "微知(上海)服務外包有限公司" } { "index": { "_id": 2 }} { "companyId": "55", "customerName": "上海微盟" } { "index": { "_id": 3 }} { "companyId": "55", "customerName": "上海知道廣告有限公司" } { "index": { "_id": 4 }} { "companyId": "55", "customerName": "微鯨科技有限公司" } { "index": { "_id": 5}} { "companyId": "55", "customerName": "北京微塵大業電子商務" } { "index": { "_id": 6}} { "companyId": "55", "customerName": "福建微衝企業諮詢有限公司" } { "index": { "_id": 7}} { "companyId": "55", "customerName": "上海知盛企業管理諮詢有限公司" } GET /customer/_doc/_search { "query": { "match": { "customerName": "知道" } } } GET /customer/_doc/_search { "query": { "match": { "customerName": "微知" } } }
標題 | 連接 |
---|---|
elasticsearch系列一:elasticsearch(ES簡介、安裝&配置、集成Ikanalyzer) | http://www.javashuo.com/article/p-seoiweer-mh.html |
elasticsearch系列二:索引詳解(快速入門、索引管理、映射詳解、索引別名) | http://www.javashuo.com/article/p-mnkeqnhg-mh.html |
elasticsearch系列三:索引詳解(分詞器、文檔管理、路由詳解(集羣)) | http://www.javashuo.com/article/p-hewbfjdl-mh.html |
elasticsearch系列四:搜索詳解(搜索API、Query DSL) | http://www.javashuo.com/article/p-bxhmnxve-hr.html |
elasticsearch系列五:搜索詳解(查詢建議介紹、Suggester 介紹) | http://www.javashuo.com/article/p-hbibvwze-mh.html |
elasticsearch系列六:聚合分析(聚合分析簡介、指標聚合、桶聚合) | http://www.javashuo.com/article/p-pcwdcicw-mh.html |
elasticsearch系列七:ES Java客戶端-Elasticsearch Java client | http://www.javashuo.com/article/p-hlgrwnon-ey.html |
elasticsearch系列八:ES 集羣管理(集羣規劃、集羣搭建、集羣管理) | http://www.javashuo.com/article/p-hubkyqjz-mh.html |