互动
:什么是搜索:(架构师课程里有)
可以互动
:为什么要使用esspring 短视频
如果用普通数据库,单表可以存多少数据比较合适?这个主要看自己自身业务,一般来说,1000万左右,但是6-700万的样子就可以开始逐步计划做数据库优化分库分表等
。普通搜索基于数据库,数据库单表存储能力有限,数据量越多,搜索性能越低下文档的数据如何体现,或者说是怎样的数据格式?
stu_index: [
stu_doc: {
id: 1001,
name: jack,
age: 19
},
{
id: 1002,
name: lucy,
age: 18
},
{
id: 1003,
name: lily,
age: 17
},
{
id: 1004,
name: lilei,
age: 20
}
]
https://github.com/mobz/elasticsearch-head#running-with-built-in-server
https://www.imooc.com/article/286936 这个基于centos6,架构师课程基于centos7
索引名: friends
shard = primary shard(主分片) replica = replica shard(副本分片)
演示使用head来进行索引的创建
不同的颜色表示es不同的健康程度
那么接下来我们可以通过地图来拾取一些坐标,当然如果是在app上,用户在进行搜索的时候,是会通过手机来获得当前的坐标点,通过这个坐标点来进行相关的搜索业务的。
POST /friends/_mapping (es6为/friends/_doc/_mapping)
{
"properties": {
"userId": {
"type": "long"
},
"userName": {
"type": "text"
},
"geo": {
"type": "geo_point"
},
"place": {
"type": "text"
}
}
}
POST /friends/_doc/{useId}
# 南京夫子庙
{
"userId": 1001,
"userName": "Iron Man",
"geo": {
"lon": 118.795263,
"lat": 32.02705
},
"place": "南京夫子庙"
}
# 南京书店
{
"userId": 1002,
"userName": "Thor",
"geo": {
"lon": 118.795708,
"lat": 32.027092
},
"place": "南京书店"
}
# 盐水鸭
{
"userId": 1003,
"userName": "Steve",
"geo": {
"lon": 118.796134,
"lat": 32.027861
},
"place": "盐水鸭"
}
# 鸡鸣寺
{
"userId": 1004,
"userName": "SpiderMan",
"geo": {
"lon": 118.801893,
"lat": 32.067251
},
"place": "鸡鸣寺"
}
# 南京古生物博物馆
{
"userId": 1005,
"userName": "BlackWidow",
"geo": {
"lon": 118.801592,
"lat": 32.065931
},
"place": "南京古生物博物馆"
}
# 鸡鸣山庄
{
"userId": 1006,
"userName": "Hawkeye",
"geo": {
"lon": 118.798659,
"lat": 32.068096
},
"place": "鸡鸣山庄"
}
# 北极阁公园
{
"userId": 1007,
"userName": "Hulk",
"geo": {
"lon": 118.797105,
"lat": 32.066134
},
"place": "北极阁公园"
}
# 南京大学
{
"userId": 1008,
"userName": "Magneto",
"geo": {
"lon": 118.797105,
"lat": 32.066134
},
"place": "南京大学"
}
# 南京邮电大学
{
"userId": 1009,
"userName": "GreenArrow",
"geo": {
"lon": 118.936814,
"lat": 32.121167
},
"place": "南京邮电大学"
}
# 南京师范大学
{
"userId": 1010,
"userName": "BatMan",
"geo": {
"lon": 118.916549,
"lat": 32.111014
},
"place": "南京师范大学"
}
DELETE /friends/_doc/{id}
POST /my_doc/_doc/1/_update
{
"doc": {
"name": "慕课"
}
}
PUT /my_doc/_doc/1
{
"id": 1001,
"name": "imooc-1",
"desc": "imooc is very good, 慕课网非常牛!",
"create_date": "2019-12-24"
}
以左上
和右下
为基准所画的矩阵中,只要包含geo坐标点,就会被查询出来
GET /friends/_doc/_search
{
"query": {
"geo_bounding_box": {
"geo": {
"top_left": {
"lon": 118.789703,
"lat": 32.030249
},
"bottom_right": {
"lon": 118.802171,
"lat": 32.024341
}
}
}
}
}
使用场景:大气环境监测,国控的,激光雷达设备所组成的一个范围
GET /friends/_doc/_search
{
"query": {
"geo_polygon": {
"geo": {
"points": [
{"lon": 118.798533, "lat": 32.029269},
{"lon": 118.797221, "lat": 32.028427},
{"lon": 118.792748, "lat": 32.02555},
{"lon": 118.799449, "lat": 32.025634}
]
}
}
}
}
互动
:使用场景最多,比如:
GET /friends/_doc/_search
{
"query": {
"geo_distance": {
"distance": "50m/1km/10km",
"geo": {
"lon": 118.795739,
"lat": 32.026973
}
}
}
}
常用于主动的推荐:
用于统计距离某个点位置100米,500米,2公里范围内的坐标数量。 单位:一般用km或m
GET /friends/_doc/_search
{
"size": 0,
"aggs": {
"tongji": {
"geo_distance": {
"distance_type": "plane",
"field": "geo",
"origin": {
"lon": 118.79549,
"lat": 32.027042
},
"unit": "km",
"ranges": [
{
"from": 0,
"to": 1
},
{
"from": 1,
"to": 5
},
{
"from": 5,
"to": 100
}
]
}
}
}
}