ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索引擎。
wget .4.
tar -xvzf elasticsearch-6.4.
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.
#
再次启动报错:
[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]
解决方案:
vi /etc/f # 添加两行行配置,并重连SSH
elasticsearch soft nofile 65536
elasticsearch hard nofile 65537vi /f # 添加一行配置
vm.max_map_count=262144
sysctl -p
地址:
192.168.141.129:9200/?pretty
显示:
.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 | 查看所有的索引状态 |
直接创建
PUT twitter
settings
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 核心类型
stringtext and keyword
Numeric datatypeslong, integer, short, byte, double, float, half_float, scaled_float
Date datatypedate
Boolean datatypeboolean
Binary datatypebinary
Range datatypes 范围integer_range, float_range, long_range, double_range, date_rangeComplex datatypes 复合类型
Array datatype数组就是多值,不需要专门的类型
Object datatypeobject :表示值为一个JSON 对象
Nested datatypenested:for arrays of JSON objects(表示值为JSON对象数组 )Geo datatypes 地理数据类型
Geo-point datatypegeo_point: for lat/lon points (经纬坐标点)
Geo-Shape datatypegeo_shape: for complex shapes like polygons (形状表示)Specialised datatypes 特别的类型
IP datatypeip: for IPv4 and IPv6 addresses
Completion datatypecompletion: to provide auto-complete suggestions
Token count datatypetoken_count: to count the number of tokens in a string
mapper-murmur3murmur3: to compute hashes of values at index-time and store them in the index
Percolator typeAccepts queries from the query-dsl
join datatypeDefines 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) | .html |
elasticsearch系列二:索引详解(快速入门、索引管理、映射详解、索引别名) | .html |
elasticsearch系列三:索引详解(分词器、文档管理、路由详解(集群)) | .html |
elasticsearch系列四:搜索详解(搜索API、Query DSL) | .html |
elasticsearch系列五:搜索详解(查询建议介绍、Suggester 介绍) | .html |
elasticsearch系列六:聚合分析(聚合分析简介、指标聚合、桶聚合) | .html |
elasticsearch系列七:ES Java客户端-Elasticsearch Java client | .html |
elasticsearch系列八:ES 集群管理(集群规划、集群搭建、集群管理) | .html |
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
博文来源广泛,如原作者认为我侵犯知识产权,请尽快给我发邮件 359031282@qq联系,我将以第一时间删除相关内容。
本文发布于:2024-01-31 22:12:32,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170671035131724.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |