elasticsearch学习笔记——学习笔记(一)

根据官网文档整理的一点学习笔记,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
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值