ElasticSearch高级查询

https://www.imooc.com/video/15759/0

ElasticSearch查询

1,子条件查询:特定字段查询所指特定值

1.1query context,有_score
1.1.1全文本查询,针对文本类型数据
1.1.1.1 模糊匹配
POST http://127.0.0.1/book/_search
{
"query":{
"match":{
"author":"瓦力"
}
}
}
{
"query":{
"match":{
"title":"ElasticSearch入门"
}
}
} 1.1.1.2 习语匹配
{
"query":{
"match_phrase":{
"title":"ElasticSearch入门"
}
}
} 1.1.1.3 多字段匹配
{
"query":{
"multi_match":{
"query":"瓦力",
"fields":["author","title"]
}
}
} 1.1.1.4 语法查询
{
"query":{
"query_string":{
"query":"ElasticSearch AND 大法"
}
}
} {
"query":{
"query_string":{
"query":"(ElasticSearch AND 大法) OR Python"
}
}
} {
"query":{
"query_string":{
"query":"瓦力 OR ElasticSearch",
"fields":["title","author"]
}
}
}
1.1.2字段级别查询,针对结构化数据,如数字、日期等 {
"query":{
"term":{
"word_count":1000
}
}
} {
"query":{
"term":{
"author":"瓦力"
}
}
}
{
"query":{
"range":{
"word_count":{
"gte":1000,
"lte":2000
}
}
}
}
{
"query":{
"range":{
"word_count":{
"gt":1000,
"lte":2000
}
}
}
}
{
"query":{
"range":{
"publish_date":{
"gte":"2017-01-01",
"lte":"2017-12-31"
}
}
}
}
{
"query":{
"range":{
"publish_date":{
"gte":"2017-01-01",
"lte":"now"
}
}
}
}
1.2filter context
filter表示查找是不是 {
"query": {
"bool": {
"filter": {
"term": {
"word_count": 1000
}
}
}
}
} 2,复合条件查询:以一定的逻辑组合子条件查询 2.1 固定分数查询
{
"query": {
"match": {
"title": "ElasticSearch"
}
}
} {
"query": {
"constant_score": {
"filter": {
"match": {
"title": "ElasticSearch"
}
}
}
}
} {
"query": {
"constant_score": {
"filter": {
"match": {
"title": "ElasticSearch"
}
},
"boost": 2
}
}
} 2.2 bool查询 should - 表示 或者
{
"query": {
"bool": {
"should": [
{
"match":{
"author": "瓦力"
}
},
{
"match": {
"title": "ElasticSearch"
} } ]
}
}
} must - 表示 必须 {
"query": {
"bool": {
"must": [
{
"match":{
"author": "瓦力"
}
},
{
"match": {
"title": "ElasticSearch"
} } ]
}
}
} {
"query": {
"bool": {
"must": [
{
"match":{
"author": "瓦力"
}
},
{
"match": {
"title": "ElasticSearch"
} } ],
"filter": [
{
"term": {
"word_count": 1000
}
}
]
}
}
}
{
"query": {
"bool": {
"must_not": {
"term": {
"author": "瓦力"
}
}
}
}
}

https://www.imooc.com/video/15759/0
ElasticSearch查询

1,子条件查询:特定字段查询所指特定值
1.1query context,有_score1.1.1全文本查询,针对文本类型数据1.1.1.1 模糊匹配POST http://127.0.0.1/book/_search{    "query":{        "match":{            "author":"瓦力"        }    }}{    "query":{        "match":{            "title":"ElasticSearch入门"        }    }}

1.1.1.2 习语匹配{    "query":{        "match_phrase":{            "title":"ElasticSearch入门"        }    }}
1.1.1.3 多字段匹配{    "query":{        "multi_match":{            "query":"瓦力",            "fields":["author","title"]        }    }}
1.1.1.4 语法查询{    "query":{        "query_string":{            "query":"ElasticSearch AND 大法"        }    }}
{    "query":{        "query_string":{            "query":"(ElasticSearch AND 大法) OR Python"        }    }}
{    "query":{        "query_string":{            "query":"瓦力 OR ElasticSearch",            "fields":["title","author"]        }    }}1.1.2字段级别查询,针对结构化数据,如数字、日期等
{    "query":{        "term":{            "word_count":1000        }    }}
{    "query":{        "term":{            "author":"瓦力"        }    }}{    "query":{        "range":{            "word_count":{                "gte":1000,                "lte":2000            }        }    }}{    "query":{        "range":{            "word_count":{                "gt":1000,                "lte":2000            }        }    }}{    "query":{        "range":{            "publish_date":{                "gte":"2017-01-01",                "lte":"2017-12-31"            }        }    }}{    "query":{        "range":{            "publish_date":{                "gte":"2017-01-01",                "lte":"now"            }        }    }}1.2filter contextfilter表示查找是不是
{"query": {"bool": {"filter": {"term": {"word_count": 1000}}}}}

2,复合条件查询:以一定的逻辑组合子条件查询

2.1 固定分数查询{"query": {"match": {"title": "ElasticSearch"}}}
{"query": {"constant_score": {"filter": {"match": {"title": "ElasticSearch"}}}}}
{"query": {"constant_score": {"filter": {"match": {"title": "ElasticSearch"}},"boost": 2}}}
2.2 bool查询
should - 表示 或者{"query": {"bool": { "should": [{"match":{"author": "瓦力"}},{"match": {"title": "ElasticSearch"}}]}}}
must - 表示 必须
{"query": {"bool": { "must": [{"match":{"author": "瓦力"}},{"match": {"title": "ElasticSearch"}}]}}}
{"query": {"bool": { "must": [{"match":{"author": "瓦力"}},{"match": {"title": "ElasticSearch"}}],"filter": [{"term": {"word_count": 1000}}]}}}{"query": {"bool": { "must_not": {"term": {"author": "瓦力"}}}}}

ElasticSearch高级查询的更多相关文章

  1. elasticsearch 高级查询

    高级查询 子条件查询 (特定字段查询所指特定值) 复合条件查询 (以一定的逻辑组合子条件查询) 一.子条件查询 子条件查询分为 query context.filter context 1.query ...

  2. 031 Spring Data Elasticsearch学习笔记---重点掌握第5节高级查询和第6节聚合部分

    Elasticsearch提供的Java客户端有一些不太方便的地方: 很多地方需要拼接Json字符串,在java中拼接字符串有多恐怖你应该懂的 需要自己把对象序列化为json存储 查询到结果也需要自己 ...

  3. java整合Elasticsearch,实现crud以及高级查询的分页,范围,排序功能,泰文分词器的使用,分组,最大,最小,平均值,以及自动补全功能

    //为index创建mapping,index相当于mysql的数据库,数据库里的表也要给各个字段创建类型,所以index也要给字段事先设置好类型: 使用postMan或者其他工具创建:(此处我使用p ...

  4. Elasticsearch 数据查询

    数据准备: PUT /shop { "settings": { "number_of_shards": 3, "number_of_replicas& ...

  5. 测试使用索引库crud和高级查询分页

    1.搭建ES的服务 导入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifa ...

  6. MongoDB高级查询详细

    前言 前几篇,老玩家绕道即可,新手晚上闲着也是蛋疼,不如把命令敲一边,这样你就会对MongoDB有一定的掌握啦.如果没有安装MongoDB去看我的上一篇博客  MongoDB下载安装与简单增删改查 前 ...

  7. T-SQL高级查询语句

    高级查询 1.连接查询,对结果集列的扩展select * from info select * from info,nation #形成笛卡尔积select * from info,nation wh ...

  8. SQL Server高级查询

    简介 关于数据库,我们经常会听说"增查删改"之类的词语,听起来很简单,但是如果想要准确的获取到需要的数据的话,还是要花点功夫的.下面由我来和大家谈谈高级查询的用法以及和普通查询的区 ...

  9. mongodb高级查询

    前几篇,老玩家绕道即可,新手晚上闲着也是蛋疼,不如把命令敲一边,这样你就会对MongoDB有一定的掌握啦.如果没有安装MongoDB去看我的上一篇博客  MongoDB下载安装与简单增删改查 前奏:启 ...

随机推荐

  1. java中的UDP总结

    先说一下关于InetAddress类,用一个小例子: import java.net.InetAddress; import java.net.UnknownHostException; public ...

  2. vue刨坑(二)

    vue实例 vue实例 每一个应用都是通过vue这个构造函数创建根实例(root instance),启动 new vue(选项对象) 需要传入选项对象,对象包含挂载元素,数据,模板,方法等. el: ...

  3. Mysql性能优化【转】

    mysql的性能优化无法一蹴而就,必须一步一步慢慢来,从各个方面进行优化,最终性能就会有大的提升. Mysql数据库的优化技术 对mysql优化是一个综合性的技术,主要包括 表的设计合理化(符合3NF ...

  4. AtCoder Grand Contest 018 A

    A - Getting Difference Time limit時間制限 : 2sec / Memory limitメモリ制限 : 256MB 配点 : 300 点 問題文 箱に N 個のボールが入 ...

  5. 学习webservice

    客户端测试页: WebService代码: using System; using System.Collections.Generic; using System.Linq; using Syste ...

  6. POCO库中文编程参考指南(6)Poco::Timestamp

    1 类型别名 三个时间戳相关的类型别名,TimeDiff表示两个时间戳的差,第二个是以微秒为单位的时间戳,第三个是以 100 纳秒(0.1 微妙)为单位的时间戳: typedef Int64 Time ...

  7. 如何让natTable表格支持自定义多个右键菜单

    在nebula中,官方默认提供了一个构造natTable的builder类,并且提供了一个debugInfo的默认右键菜单,但是当我们通过官方提供的builder去创建natTable,并且要添加多个 ...

  8. Fiddler抓包3-查看get与post请求【转载】

    本篇转自博客:上海-悠悠 原文地址:http://www.cnblogs.com/yoyoketang/p/6719717.html 前言 前面两篇关于Fiddler抓包的一些基本配置,配置完之后就可 ...

  9. nagios部署+短信和邮件报警

    操作系统 CentOS6.6  服务端:10.0.0.20 客户端:10.0.0.50 一.nagios的服务端安装部署 1.nagios安装 [root@manager src]# rzrz wai ...

  10. ubuntu16下安装telnet和opensshserver

    安装了虚拟机,使用的是ubuntu 16,server版本. 启动后发现没有telnet和ssh,就安装了(netstat -a|grep telnet). apt-get install openb ...