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 |