栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

elasticsearch学习笔记

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
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/758701.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号