Elasticsearch 全文搜索
1,匹配查询(match)
match查询主要的应用场景是进行全文搜索;
// 1,初始化数据
DELETE /my_index
PUT /my_index
{ "settings": { "number_of_shards": 1 }}
POST /my_index/my_type/_bulk
{ "index": { "_id": 1 }}
{ "title": "The quick brown fox" }
{ "index": { "_id": 2 }}
{ "title": "The quick brown fox jumps over the lazy dog" }
{ "index": { "_id": 3 }}
{ "title": "The quick brown fox jumps over the quick dog" }
{ "index": { "_id": 4 }}
{ "title": "Brown fox brown dog" }
// 2,match 单个词查询
GET /my_index/my_type/_search
{
"query":{
"match":{
"title":"QUICK!"
}
}
}
// 3,match 多词查询
GET /my_index/my_type/_search
{
"query":{
"match":{
"title":"BROWN DOG!"
}
}
}
// 3.1 operator 操作符,默认值为or
GET /my_index/my_type/_search
{
"query":{
"match":{
"title":{
"query":"BROWN DOG!",
"operator":"and"
}
}
}
}
// 3.2 minimum_should_match 最小匹配参数
GET /my_index/my_type/_search
{
"query":{
"match":{
"title":{
"query":"quick brown dog",
"minimum_should_match": "75%"
}
}
}
}
2,组合查询
// 组合查询
GET /my_index/my_type/_search
{
"query":{
"bool":{
"must":{"match":{"title":"quick"}},
"must_not":{"match":{"title":"lazy"}},
"should":[
{"match":{"title":"brown"}},
{"match":{"title":"dog"}}
]
}
}
}
// 备注:should语句,一个文档不必包含“brown”或“dog”这两个词项,但如果一旦包含,它的相关性会提高。
// 控制精度(minimum_should_match)
GET /my_index/my_type/_search
{
"query":{
"bool":{
"should":[
{"match":{"title":"brown"}},
{"match":{"title":"fox"}},
{"match":{"title":"dog"}}
],
"minimum_should_match": 2
}
}
}
3,查询语句提升权重
// boost 控制查询语句的相对权重,默认值为1,大于1会提升一个语句的相对权重
GET /_search
{
"query": {
"bool": {
"must": {
"match": {
"content": {
"query": "full text search",
"operator": "and"
}
}
},
"should": [
{ "match": {
"content": {
"query": "Elasticsearch",
"boost": 3
}
}},
{ "match": {
"content": {
"query": "Lucene",
"boost": 2
}
}}
]
}
}
}
4,控制分析
// 1,新增字段,并配置分析器
PUT /my_index/_mapping/my_type
{
"my_type": {
"properties": {
"english_title": {
"type": "text",
"analyzer": "english"
}
}
}
}
// 2,validate-query API 分析查询过程
GET /my_index/my_type/_validate/query?explain
{
"query":{
"bool":{
"should":[
{"match":{"title":"Foxes"}},
{"match":{"english_title": "Foxes"}}
]
}
}
}
参考资料:
-FORBIDDEN 12 index read-only allow delete (api)
-全文检索
Elasticsearch 全文搜索的更多相关文章
- Elasticsearch全文搜索——adout
现在尝试下稍微高级点儿的全文搜索——一项传统数据库确实很难搞定的任务. 搜索下所有喜欢攀岩(rock climbing)的雇员: curl -XGET 'localhost:9200/megacorp ...
- [Elasticsearch] 全文搜索 (一) 基础概念和match查询
全文搜索(Full Text Search) 现在我们已经讨论了搜索结构化数据的一些简单用例,是时候开始探索全文搜索了 - 如何在全文字段中搜索来找到最相关的文档. 对于全文搜索而言,最重要的两个方面 ...
- Elasticsearch 全文搜索和keyword search字段的mapping定义
在ES5.0之前我们对于需要keyword search的字段都是这样定义的: { "field name":{ "type": "string&qu ...
- elasticsearch全文搜索
1.创建索引 PUT 192.168.100.102:9200/news 2.创建mapping POST 192.168.100.102:9200/news/new/_mapping { " ...
- ElasticSearch全文搜索引擎(A)
文章:[Elasticsearch] 全文搜索 (一) - 基础概念和match查询 全文检索,是从最初的字符串匹配和简单的布尔逻辑检索技术,演进到能对超大文本.语音.图像.活动影像等非结构化数据进行 ...
- 全文搜索之 Elasticsearch
概述 Elasticsearch (ES)是一个基于 Lucene 的开源搜索引擎,它不但稳定.可靠.快速,而且也具有良好的水平扩展能力,是专门为分布式环境设计的. 特性 安装方便:没有其他依赖,下载 ...
- 在 Laravel 项目中使用 Elasticsearch 做引擎,scout 全文搜索(小白出品, 绝对白话)
项目中需要搜索, 所以从零开始学习大家都在用的搜索神器 elasiticsearch. 刚开始 google 的时候, 搜到好多经验贴和视频(中文的, 英文的), 但是由于是第一次接触, 一点概念都没 ...
- 使用ElasticSearch服务从MySQL同步数据实现搜索即时提示与全文搜索功能
最近用了几天时间为公司项目集成了全文搜索引擎,项目初步目标是用于搜索框的即时提示.数据需要从MySQL中同步过来,因为数据不小,因此需要考虑初次同步后进行持续的增量同步.这里用到的开源服务就是Elas ...
- ASP.NET Web API + Elasticsearch 6.x 快速做个全文搜索
最近想做个全文搜索,设想用 ASP.NET Web API + Elasticsearch 6.x 来实现. 网上搜了下 Elasticsearch 的资料,大部分是讲 linux 平台下如何用 ja ...
随机推荐
- mysql group by order by havaing where 顺序
结论: select xx from xx where xx group by xx order by xxx; select xx from xx group by xx having xx ord ...
- Pytest权威教程02-Pytest 使用及调用方法
目录 Pytest 使用及调用方法 使用python -m pytest调用pytest 可能出现的执行退出code 获取版本路径.命令行选项及环境变量相关帮助 第1(N)次失败后停止测试 指定及选择 ...
- SpringCloud:Zipkin链路追踪,并将数据写入mysql
1.zipkin server 1.1.新建Springboot项目,zinkin 1.2.添加依赖 <dependency> <groupId>io.zipkin.java& ...
- Linux下的find命令详解
0x01 简介 find命令用来在指定目录下查找文件.任何位于参数之前的字符串都将被视为欲查找的目录名.如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件.并且将查找到的子 ...
- python 的小技巧之统计list里面元素的个数
一般写法 def count_list(std:list,tongji): i=0 for item in std: if item==tongji: i+=1 print(i) if __name_ ...
- layer.msg如何让按钮的回调执行完毕后弹框不自动关闭
问题出现:我点击“确定”时会验证“新手机号码”,如果验证不通过则不给该弹框关掉,但是实际操作时,不管验证怎么样,点击“确定”之后该弹框都会关掉. 之前的写法: layer.open({ ...
- 前端 img标签显示 base64格式的 图片
本文链接:https://blog.csdn.net/kukudehui/article/details/80409522在做项目的时候,我从后端返回了一个base64格式的图片文件,想把它渲染在前端 ...
- IDEA一些自动补全方式
第一种:系统自带:可以CTRL + j 可以查看 psvm 也就是public static void main的首字母. 依次还有在方法体内键入for会有一个fori的提示,选中然后tab键,就会自 ...
- C3线性化
https://zh.wikipedia.org/wiki/C3线性化 在计算机科学中,C3算法主要用于确定多重继承时,子类应该继承哪一个父类的方法,即方法解析顺序(Method Resolution ...
- mysql - ERROR 1114 (HY000): The table is full
mysql - ERROR 1114 (HY000): The table is full - Stack Overflowhttps://stackoverflow.com/questions/73 ...