1010 elasticsearch 概念 搭建

es 节点类型

客服端节点  智能负载均衡 调节数据节点和主节点 处理路由请求 分发索引 处理搜索 

数据节点  存贮索引数据节点 对文档进行增删改查 ,聚合等操作 

主节点  处理和集群有管的操作 如创建 删除索引 

索引  类似于数据库  是一组文档的集合 索引的数据结构也就是倒排索引 

类型  类似于数据库中的表  一个索引中可以定义一种或多种类型,一个类型是索引的一个逻辑分类或分区 也是一类文档的集合

文档 类似于数据库中的记录 一个文档是一个可被索引的基础单元 文档都是json类型

主节点选举  

master失联的同时master的候选节点达到设置的值时 产生选举

如何索引文档  https://www.cnblogs.com/xi-jie/articles/10531532.html  倒排索引  由es创建一些 序号 

什么是b+树  比b树 多了一组专门用来索引的数据  https://www.cnblogs.com/dongguacai/p/7241860.html

操作es  通过curl对es进行操作

写数据  curl -XPUT node2:9200/blog/article/1?pretty -d '{"title":"java虚拟机"}'    数据库/表/id  -d 后文档内容

新建文档 

curl -XPOST node3:9200/blog/article/1?pretty -d '{"id":1,"title":"Git 简介","posttime":"2017-05-01","content":"Git是一款免费、开源的分布式版本控制系统"}'    如果不指定id/1  他会自动生成id

根据id获取多个文档 

curl node2:9200/_mget?pretty -d '{"docs":[{"_index":"blog","_type":"article","_id":"1"},

{"_index":"blog","_type":"article","_id":"101"},{"_index":"blog","_type":"article","_id":"102"}]}'

可以通过node2:9200/后面的地址简化获取文档方式 node2:9200/blog/article/_mget

映射  相当于数据库字段类型 

curl -XPOST node2:9200/_bulk?pretty --data-binary @books.json  从本地books.json导入数据

curl node2:9200/books/_search?pretty -d '{"query":{"match_all":{}}}'  查询 = curl node2:9200/books/_search?pretty

term 查询用来查找指定字段中包含给定单词的文档  同时可以分页  限制返回哪些字段  设置高亮

curl node2:9200/books/_search?pretty -d '{"from":0,"szie":10,"_source":["title","auther"],"query":{"term":{"title":"思想"}},"highlight":{"fields":{"title":{}}} }'

match query 会对查询语句进行分词 分词后匹配任意一项 or   只匹配所有关键词 and

curl node2:9200/books/_search?pretty -d '{"query":{ "match":{"title":{"query":"java编程思想", "operator":"and"}}}}' 全匹配“java编程思想”

match_phrase会把query内容分词,分词器可以自定义 满足以下的能被搜索到(分词后所有词项都要出现  词项顺序一致)

curl node2:9200/test/_search?pretty -d '{  "query":{"match_phrase":{  "foo":"hello world"}}}'

match_phrase_prefix 和 match_phrase类似 额外支持最后一个词项的前缀匹配

curl node2:9200/test/_search?pretty -d '{  "query":{    "match_phrase_prefix":{  "foo":"hello w"}}}'

multi_match 在match的基础上 可以搜索多个字段  (查询范围在 title 和  description)可以支持对搜索的字段使用通配符如 *

curl node2:9200/books/_search?pretty -d'{  "query":{    "multi_match":{      "query":"java编程",      "fields":[ "title", "description" ]}}}’

bool查询 must 相当于and  should相当于 or  must_not 与must 相反  filter过滤相当于and 但不参与评分

curl node2:9200/books/_search?pretty -d '{  "query":{    "bool":{      "minimum_should_match":1,      "must":{        "match":{"title": "java"}      },      "should":[        {"match":{"description":"虚拟机"}}      ],      "must_not":{     "range":{"price":{"gte":70}}}}}}'

 

elasticsearch java api 体会

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值