mysql自增主键在大量删除后如何重新设置避免断层
@ResponseBody的作用
@Transactional 注解,要么都成功要么都失败

bin/elasticsearch 启动elasticsearch
netstat -an | grep 9200 查看elasticsearch默认9200端口
bin/kibana 启动kibana
bin/elasticsearch -d 后台启动
tail -f dianping-app.log
kill -9
bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.3.0/elasticsearch-analysis-ik-7.3.0.zip

bin/logstash-plugin install logstash-input-jdbc

./logstash -f mysql/jdbc.conf

//增加 my.cnf配置
server-id = 1
binlog_format = ROW
log_bin = mysql_bin

show variables like ‘log_bin’; 开启logbin
mvn clean package -DskipTests

GET /shop/_search

//非结构化新建索引

PUT /movie
{"settings": {"number_of_shards": 1,"number_of_replicas": 1},"mappings": {"properties": {"title":{"type":"text","analyzer": "english"},"tagline":{"type":"text","analyzer": "english"},"release_date":{"type":"date","format": "8yyyy/MM/dd||yyyy/M/dd||yyyy/MM/d||yyyy/M/d"},"popularity":{"type":"double"},"overview":{"type":"text","analyzer": "english"},"cast":{"type":"object","properties": {"character":{"type":"text","analyzer":"standard"},"name":{"type":"text","analyzer":"standard"}}}}}
}

//搜索内容match

GET /movie/_search
{"query": {"match": {"title": "steve"}}
}

//term 查询 不进行分词分析,直接去索引内查询

GET /movie/_search
{"query": {"term":{"title":"steve zissou"}}
}

//分词后的and和or逻辑 match 默认使用的是or

GET /movie/_search
{"query":{"match": {"title": "basketball with cartoom aliens"}}
}

// 改成and

GET /movie/_search
{"query":{"match": {"title": "basketball with cartoom aliens","operator": "and"}}
}

//最小词匹配项

GET /movie/_search
{"query":{"match": {"title": {"query":"basketball love aliens","operator": "or","minimum_should_match": 2}}}
}

//短语查询

GET /movie/_search
{"query": {"match": {"title": "steve zissou"}}
}GET /movie/_analyze
{"field": "title","text":"steven zissou"
}GET /movie/_search
{"explain": true, "query": {"term":{"title":"steve"}}
}

#多字段查询

GET /movie/_search
{"query":{"multi_match": {"query": "basketball with cartoom aliens","fields": ["title","overview"]}}
}

#优化多字段查询

GET /movie/_search
{"explain": true, "query":{"multi_match": {"query": "basketball with cartoom aliens","fields": ["title^10","overview"],"tie_breaker": 0.3}}
}

#bool查询
#must:必须都为true
#should:其中只有一个为true即可
#为true的越多则得分越高

GET /movie/_search
{"query": {"bool":{"should":[{"match":{"title":"basketball with cartoom aliens"}},{"match": {"overview": "basketball with cartoom aliens"}}]}}
}

#不同的multi_query其实是有不同的type
#best_fields:默认的得分方式,取得最高的分数作为对应文档的对应分数,“最匹配模式”,dis_max

GET /movie/_search
{"explain": true,"query":{"multi_match": {"query": "basketball with cartoom aliens","fields": ["title","overview"],"type":"best_fields"}}
}
GET /movie/_search
{"explain": true, "query": {"dis_max":{"queries":[{"match":{"title":"basketball with cartoom aliens"}},{"match": {"overview": "basketball with cartoom aliens"}}]}}
}

#most_fields:考虑绝大多数(所有的)文档的字段得分相加获得想要的结果

GET /movie/_search
{"explain": true,"query":{"multi_match": {"query": "basketball with cartoom aliens","fields": ["title^10","overview^0.1"],"type":"most_fields"}}
}
GET /movie/_validate/query?explain
{"query": {"multi_match": {"query": "basketball with cartoom alien","fields": ["title^10","overview^0.1"],"type":"most_fields"}}
}

#cross_fields:以分词为单位计算栏位的总分,适用于词导向的匹配

GET /movie/_search
{"explain": true,"query":{"multi_match": {"query": "steve job","fields": ["title","overview"],"type":"cross_fields"}}
}
#query string
#方便的利用 and or not
GET /movie/_search
{"query": {"query_string": {"fields":["title"],"query": "steve OR jobs"}}
}

#filter过滤查询
#单条件过滤

GET /movie/_search
{"query":{"bool":{"filter": {"term": {"title": "steve"}}}}
}

#多条件过滤

GET /movie/_search
{"query":{"bool":{"filter": [{"term":{"title":"steve"}},{"term":{"cast.name":"gaspard"}},{"range":{"release_date": {"lte":"2015/01/01"}}},{"range":{"popularity":{"gte":"25"}}}]}},"sort":[{"popularity": {"order":"desc"}}]
}
#带match打分的filter
GET /movie/_search
{"query": {"bool":{"must":[{"match":{"title":"Search"}},{"match": {"title": "ElasticSearch"}}],"filter": [{"term":{"title":"steve"}}, {"term":{"cast.name":"gaspard"}},{"range": { "release_date": { "lte": "2015/01/01" }}}, {"range": { "popularity": { "gte": "25" }}}]}}
}

#functionscore

GET /movie/_search
{"explain": true, "query": {"function_score": {"query": {"multi_match": {"query": "steve job","fields": ["title","overview"],"operator":"or","type":"most_fields"}},"functions": [{"field_value_factor": {"field": "popularity","modifier": "log2p","factor": 10}},{"field_value_factor": {"field": "popularity", "modifier": "log2p","factor": 5}}],"score_mode": "sum","boost_mode": "sum" }}
}

#测试ik分词器,智能分词法

GET _analyze?pretty
{"analyzer":"ik_smart","text":"中华人民共和国国歌"
}

#最大化分词

GET _analyze?pretty
{"analyzer":"ik_max_word","text":"中华人民共和国国歌"
}

#最佳实践:索引的时候使用max_word 查询的时候使用smartword

#创建shop索引

PUT /shop
{"settings" : { "number_of_shards" : 1,        "number_of_replicas" : 1},"mappings": {"properties": {"id":{"type":"integer"},"name":{"type":"text","analyzer": "ik_max_word","search_analyzer":"ik_smart"}, "tags":{"type":"text","analyzer": "whitespace","fielddata":true}, "location":{"type":"geo_point"},"remark_score":{"type":"double"},"price_per_man":{"type":"integer"},"category_id":{"type":"integer"},"category_name":{"type":"keyword"},"seller_id":{"type":"integer"},"seller_remark_score":{"type":"double"},"seller_disabled_flag":{"type":"integer"}} }
}
GET /shop/_search
{"query":{"multi_match": {"query": "凯悦","fields": ["name"]}}
}GET /shop/_analyze
{"analyzer": "ik_smart","text":"凯悦"
}GET /shop/_analyze
{"analyzer": "ik_max_word","text":"花悦庭果木烤鸭"
}#带上距离字段
GET /shop/_search
{"query": {"match": {"name": "凯悦"}},"_source":"*","script_fields": {"distance":{"script":{"source":"haversin(lat,lon,doc['location'].lat,doc['location'].lon)","lang":"expression","params":{"lat":31.37,"lon":127.12}}}}
}
#排序
GET /shop/_search
{"query": {"match": {"name": "凯悦"}},"_source":"*","script_fields": {"distance":{"script":{"source":"haversin(lat,lon,doc['location'].lat,doc['location'].lon)","lang":"expression","params":{"lat":31.37,"lon":127.12}}}},"sort":[{"_geo_distance": {"location": {"lat": 31.37,"lon": 127.12},"order": "asc","unit":"km","distance_type": "arc"}}]
}#使用 function score 解决排序模型
#加入酒店类目过滤
GET /shop/_search
{"_source":"*","script_fields": {"distance":{"script":{"source":"haversin(lat,lon,doc['location'].lat,doc['location'].lon)","lang":"expression","params":{"lat":31.23916171,"lon":121.48789949}}}},"query":{"function_score": {"query": {"bool":{"must":[{"match":{"name":{"query":"凯悦","boost":"0.1"}}},{"term":{"seller_disabled_flag": 0}},{"term":{"category_id":2}}]}},"functions": [{"gauss": {"location": {"origin": "31.23916171,121.48789949","scale": "100km","offset":"0km","decay":0.5}},"weight": 9},{"field_value_factor": {"field": "remark_score"},"weight": 0.2},{"field_value_factor": {"field": "seller_remark_score"},"weight": 0.2}],"score_mode": "sum","boost_mode": "sum"}},"sort": [{"_score": {"order": "desc"}}],"aggs":{"group_by_tags":{"terms":{"field":"tags"}}}
}
#加入同义词
PUT /shop
{"settings" : { "number_of_shards" : 1,        "number_of_replicas" : 1,"analysis":{"filter":{"my_synonym_filter":{"type":"synonym","synonyms_path":"analysis-ik/synonyms.txt"}},"analyzer":{"ik_syno":{"type":"custom","tokenizer":"ik_smart","filter":["my_synonym_filter"]},"ik_syno_max":{"type":"custom","tokenizer":"ik_max_word","filter":["my_synonym_filter"]}}}},"mappings": {"properties": {"id":{"type":"integer"},"name":{"type":"text","analyzer": "ik_syno_max","search_analyzer":"ik_syno"}, "tags":{"type":"text","analyzer": "whitespace","fielddata":true}, "location":{"type":"geo_point"},"remark_score":{"type":"double"},"price_per_man":{"type":"integer"},"category_id":{"type":"integer"},"category_name":{"type":"keyword"},"seller_id":{"type":"integer"},"seller_remark_score":{"type":"double"},"seller_disabled_flag":{"type":"integer"}} }
}GET /shop/_search
{"query": {"match": {"name": "锡伯"}}
}GET /shop/_analyzePOST /shop/_update_by_query
{"query":{"bool":{"must":[{"term":{"name":"凯"}},{"term":{"name":"悦"}}]}}
}GET /shop/_analyze
{"field": "name","text": "凯悦"
}GET /shop/_analyze
{"analyzer": "ik_max_word","text": "凯悦"
}
#引入分类
GET /shop/_search
{"_source":"*","script_fields": {"distance":{"script":{"source":"haversin(lat,lon,doc['location'].lat,doc['location'].lon)","lang":"expression","params":{"lat":31.23916171,"lon":121.48789949}}}},"query":{"function_score": {"query": {"bool":{"must":[{"bool": {"should": [{"match":{"name":{"query":"住宿","boost":"0.1"}}},{"term":{"category_id": {"value":2,"boost":0.1}}}]}},{"term":{"seller_disabled_flag": 0}}]}},"functions": [{"gauss": {"location": {"origin": "31.23916171,121.48789949","scale": "100km","offset":"0km","decay":0.5}},"weight": 9},{"field_value_factor": {"field": "remark_score"},"weight": 0.2},{"field_value_factor": {"field": "seller_remark_score"},"weight": 0.2}],"score_mode": "sum","boost_mode": "sum"}},"sort": [{"_score": {"order": "desc"}}],"aggs":{"group_by_tags":{"terms":{"field":"tags"}}}
}

随记 elasticsearch相关推荐

  1. 记一次ElasticSearch重启之后shard未分配问题的解决

    记一次ElasticSearch重启之后shard未分配问题的解决 环境 ElasticSearch6.3.2,三节点集群 Ubuntu16.04 一个名为user的索引,索引配置为:3 primar ...

  2. 记一次后端接口开发文档的组织过程(elasticsearch)

    前言:   沟通是有成本的,尤其是项目成员技术差距很大的时候,良好的代码编写必须是以文档驱动的,这是领悟软件工程精髓的必经之路.   记一次小组开发文档的组织,虽然我本人组织得不伦不类,但是也必须得给 ...

  3. 完美避坑!记一次Elasticsearch集群迁移架构实战

    作者介绍 李猛(ynuosoft),Elastic-stack产品深度用户,ES认证工程师,2012年接触Elasticsearch,对Elastic-Stack开发.架构.运维等方面有深入体验,实践 ...

  4. 记一次中台数据传输同步Elasticsearch失败的车祸现场

    目录 一.背景 二.题外话 三.开始排查 四.为什么索引处于只读状态呢? 五.如何解决 一.背景 前几天小哈在钉钉群里收到重庆业务线反馈,说是中台数据传输中间件在同步 Mysql 增量数据到 Elas ...

  5. 记一次引入Elasticsearch的系统架构实战

    前言 我曾经面试安踏的技术岗,当时面试官问了我一个问题:如果你想使用某个新技术但是领导不愿意,你怎么办? 对于该问题我相信大家就算没有面试被问到过,现实工作中同事之间的合作也会遇到. 因此从我的角度重 ...

  6. 【数据库优化】记一次引入Elasticsearch的系统架构实战

    前言 我曾经面试,当时面试官问了我一个问题:如果你想使用某个新技术但是领导不愿意,你怎么办? 对于该问题我相信大家就算没有面试被问到过,现实工作中同事之间的合作也会遇到. 因此从我的角度重新去回答这个 ...

  7. 记一次docker启动elasticsearch报错解决方法

    docker启动elasticsearch报错,启动命令及报错信息如下 启动命令如下 docker run -d --name elasticsearch-6.4.0 -p 9200:9200 -p ...

  8. ElasticSearch PPT-笔记

    2019独角兽企业重金招聘Python工程师标准>>> 06.项目实践\05ELK分布式日志应用实战\课件及笔记: 转载于:https://my.oschina.net/u/3847 ...

  9. 记一次ElasticSearch 更改 mapping 字段类型的过程

    我的个人博客:逐步前行STEP 首先,es不支持直接更改mappinng,所以,更改 mapping 实质上是重建索引. 操作步骤如下: 1.为当前这个索引old_index设置一个别名my_inde ...

最新文章

  1. 微软技术支持工程师_微软催你买电脑啦!即可+99元即可享受上门帮教服务
  2. 怎么使用oracle的加权平均数_GPA不足,怎么短期有效提升?快来收获100%录取的秘诀!...
  3. (十一)python3 只需3小时带你轻松入门——面向对象
  4. python练习题-day25
  5. 解决 sessionStroage 无法在多个标签页共享数据的问题
  6. Linux中要重启apache服务与在windows是有很大的区别,下面我们来介绍一下
  7. 9-14 ruby环境准备 操作
  8. 剑指offer面试题[35]-第一个只出现一次的字符
  9. python游戏源代码下载_python小游戏源代码_python游戏项目
  10. 网站死链接是什么,如何检测与提交?
  11. DS18B20的CRC验证算法
  12. C. Range Increments(差分)
  13. java 日期 纳秒_java – 具有纳秒的字符串日期转换
  14. 【C语言】小游戏系列——三子棋(保姆级教程)
  15. 2021-03-13 大数据课程笔记 day52
  16. 记一次腾讯TBS浏览服务集成实践
  17. [转载]屏蔽双显卡笔记本的独显
  18. lcd屏和amoled屏的优缺点 lcd屏和amoled屏哪个效果好
  19. 微分平坦(differential flatness)
  20. 你应该知道的setTimeout秘密

热门文章

  1. the source attachment does not contain the source for the file xxx.class无法关联到某个类
  2. Ubuntu 12.04下搭建Web服务器 (MySQL+PHP+Apache)(转)
  3. 数据库原理--事务(一)
  4. SpringBoot 核心知识点整理!
  5. 【jQuery笔记Part1】11-jQuery选择器
  6. 【网络安全面试题】——文件目录穿越实现特权文件读取
  7. Python模拟浏览器向 CSDN发送POST请求的方法
  8. 转行数据分析,是选Python还是R?
  9. idea2020.2中@test是怎么测试的_Sklearn 划分训练集和测试集
  10. python字符串format格式化二