《ElasticSearch权威指南》笔记 -- 入门

入门

一些基础操作:

环境:ElasticSearch 6.8.2 , PostMan

1.创建indices,types,documents,fields
PUT  http://127.0.0.1:9200/megacorp/employee/1
{
	"first_name":"John",
	"last_name":"Smith",
	"age":25,
	"about":"I love to go rock climbing",
	"interests":["sports","music"]
}

PUT  http://127.0.0.1:9200/megacorp/employee/1
{
	"first_name":"John",
	"last_name":"Smith",
	"age":25,
	"about":"I love to go rock climbing",
	"interests":["sports","music"]
}

PUT  http://127.0.0.1:9200/megacorp/employee/1
{
	"first_name":"John",
	"last_name":"Smith",
	"age":25,
	"about":"I love to go rock climbing",
	"interests":["sports","music"]
}
2.通过documentId获取文档内容:
get http://127.0.0.1:9200/megacorp/employee/1
get http://127.0.0.1:9200/megacorp/employee/2
get http://127.0.0.1:9200/megacorp/employee/3
3.进行简单的查询(本例通过last_name查询)
POST http://127.0.0.1:9200/megacorp/employee/_search
{
	"query":{
		"match":{
			"last_name":"Smith"
		}
	}
}
4.进行复杂查询(进一步过滤结果)

查找出last_name = “Smith”,并且年龄 > 30 的员工

{
	"query":{
		"bool":{
			"must":{
				"match":{
					"last_name":"Smith"
				}
			},
			"filter":{
				"range":{
					"age":{"gt":30}
				}
			}
		}
	}
}
5.全文搜索

模糊查询,会对查询词组分词,根据相关度显示查询结果

{
	"query":{
		"match":{
			"about":"rock climbing"	
		}
	}
}

词组查询

{
	"query":{
		"match_phrase":{
			"about":"rock climbing"	
		}
	}
}
6.高亮结果
{
	"query":{
		"match":{
			"about":"rock climbing"
		}
	},
	"highlight":{
		"fields":{
			"about":{}
		}
	}
}
6.聚合分析

相当于SQL中的group by

{
	"aggs":{
		"all_interests":{
			"terms":{
				"field":"interests"
			}
		}
	}
}

分级汇总:

{
	"aggs":{
		"all_interests":{
			"terms":{
				"field":"interests"
			},
			"aggs":{
				"avg_age":{
					"avg":{
						"field":"age"
					}
				}
			}
		}
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值