根据官网文档整理的一点学习笔记,elasticsearch官方文档
- 索引
类似成一个数据库,储存关系型文档
索引一个文档:讲某个文档储存到索引种 - 搜索
- 聚合
首先下载elasticsearch,然后进入下载的文件夹,执行启动脚本
./bin/elasticsearch
创建文档
curl -H "Content-type:application/json" -XPUT 'http://localhost:9200/sales/dicount/1' -d'{"name":"38festival","discountRate":"10"}'
搜索
普通搜索
curl -XGET 'http://localhost:9200/megacorp/employee/_search'
高亮搜索
就是搜索出来的关键字被一个html标签所包裹,显示为特殊格式
curl -XGET 'http://localhost:9200/megacorp/employee/_search?q=last_name:Smith'
curl -X GET "localhost:9200/megacorp/employee/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query" : {
"match_phrase" : {
"about" : "rock climbing"
}
},
"highlight": {
"fields" : {
"about" : {}
}
}
}
'
hightlight在搜索改
查询表达式搜索
curl -XGET 'http://localhost:9200/megagory/employee/_search?pretty' -H 'Content-Type: application/json' -d'{"query":{"match":{"last_name":"Smith"}}}'
curl -X GET "localhost:9200/megacorp/employee/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query" : {
"bool": {
"must": {
"match" : {
"last_name" : "smith"
}
},
"filter": {
"range" : {
"age" : { "gt" : 30 }
}
}
}
}
}
'
全文搜索
about进行全文搜索,所得结果会有一个相关性排名
curl -XGET 'http://localhost:9200/megacorp/employee/_search?pretty' -H "Content-Type:application/json" -d'{"query":{"match":{"about":"rock climbing"}}}'
短语搜索
match_phrase
正对上述,不要搜索到仅包含ock或者climbing种一项的文档,二十要搜索到“rock climbing”的文档,即使用match_phrase
curl -XGET 'http://localhost:9200/megacorp/employee/_search' -H 'Content-Type: application/json' -d'{"query":{"match_phrase":{"about":"rock climbing"}}}'
集群
获取集群健康信息
curl -XGET "http://localhost:9200/_cluster/health"
{
"cluster_name" : "elasticsearch",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 14,
"active_shards" : 14,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 2,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 87.5
}