elastic search 基本介绍

elastic search (es) 官方文档 https://www.elastic.co/guide/index.html。这篇文章分为三个部分对es进行基本介绍。1、基本概念 2、常用接口 3、常用监控组件。

1、基本概念

es 本质上是一个分布式存储系统。但是,es的侧重点在于搜索,es要解决的问题是如何能快速检索到指定检索条件的数据。es是个分布式系统,也就是个集群。集群中的节点根据作用不同分为3类。如表<1> 所示。es的API是基于HTTP协议,以JSON为数据交互格式的RESTful API。因此任何请求客户端可以用任何语言编写的HTTP协议的请求包到es集群去请求对应的服务。es系统中的术语和数据库通常使用的术语不太一样。es术语和传统数据库术语的对比图如图<1>。

节点类别名 说明 作用
client-node 客户端节点 用于查询负载均衡,将查询请求转发到对应的处理节点。
data-node 数据节点 存储数据和检索数据
master-node 主节点 协调创建索引和检索请求;节点监控等
表<1> es 中的节点类别

Relational DB -> Databases -> Tables -> Rows -> Columns
Elasticsearch -> Indices -> Types -> Documents -> Fields
     图<1> es术语和传统数据库术语的对比

2、常用接口(以下例子URI统一为:http://dest_host/es/

2.1 创建索引

PUT  URI/expert_index_test
{"mappings":{"expert_type":{"_all":{"analyzer":"ik_smart"},"properties":{"adv_count":{"index":"not_analyzed","type":"long"},"case_id":{"index":"not_analyzed","type":"long"},"category_id":{"index":"not_analyzed","type":"long"},"city_id":{"index":"not_analyzed","type":"long"},"comm_id":{"index":"not_analyzed","type":"long"},"composite_score":{"index":"not_analyzed","type":"long"},"department_id":{"index":"not_analyzed","type":"long"},"desc":{"analyzer":"ik_smart","index":"analyzed","type":"string"},"expert_status":{"index":"not_analyzed","type":"long","null_value":0},"name":{"analyzer":"ik_smart","index":"analyzed","type":"string"},"name_pinyin":{"index":"analyzed","type":"string"},"popular_id":{"index":"not_analyzed","type":"long"},"price":{"index":"not_analyzed","type":"long"},"save":{"analyzer":"ik_smart","index":"analyzed","type":"string"},"sex":{"index":"not_analyzed","type":"long"},"skill":{"analyzer":"ik_smart","index":"analyzed","type":"string"},"sort_value":{"index":"not_analyzed","type":"long"},"spoken_id":{"index":"not_analyzed","type":"long"},"tinyid":{"index":"not_analyzed","type":"string"},"topic_id":{"index":"not_analyzed","type":"long"}}}},"settings":{"number_of_replicas":2,"number_of_shards":2}}

2.2 插入一条数据

PUT /expert_index/expert_index_test/144115197398613826?op_type=create

{"adv_count":0,"category_id":[101],"city_id":0,"comm_id":[150326],"composite_score":0,"desc":"全能","expert_status":1,"name":"听说_测试号","name_pinyin":"TingShuiCeShiHao","price":1,"save":"0","sex":2,"sort_value":2,"tinyid":"3507007158","topic_id":[170002]}

2.3 更新一条数据

POST /expert_index_test/expert_type/144115197398613826/_update

{"doc":{"category_id":[0],"city_id":0,"composite_score":0,"desc":"","name":"名字","name_pinyin":"mingzi","price":0,"save":"","sex":0,"sort_value":987,"tinyid":"144115197398613826"}}

2.4 查询一条记录

GET  /expert_index_test/_search?q=_id:144115197398613826

2.4 检索数据

POST /expert_index_test/expert_type/_search?size=15&from=0

POST /expert_index_test/expert_type/_search?size=15&from=0
{"query":{"bool":{"filter":[{"term":{"category_id":2}},{"term":{"popular_id":180028}}]}},"sort":[{"sort_value":{"order":"asc"}},{"composite_score":{"order":"desc"}},{"price":{"order":"asc"}},{"name_pinyin":{"order":"asc"}}]}

2.5 删除一条记录

DELETE /expert_index_test/expert_type/144115197382188438

2.6 添加字段

PUT /expert_index_test/_mapping/expert_type
{"properties" : {"expert_status" : {"type" : "long","index": "not_analyzed"}}}

3、常用监控组件

head、marvel

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值