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. 【CF Round 439 A. The Artful Expedient】

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  2. HTML标签的使用要注意语义化

    语义化标签:你认为用什么标签最能描述这块内容,觉得这样表述更有意义,那么就可以使用这个标签. 现在的浏览器对CSS支持都挺完善的(不包括CSS3),讲究的是结构与表现相分离,结构与行为相分离,一个WE ...

  3. Hibernate中多对多的annotation的写法(中间表可以有多个字段)

    2011-07-04 6:52 一般情况下,多对多的关联关系是需要中间表的: 情况一:如果中间表仅仅是做关联用的,它里面仅有2个外键做联合主键,则使用ManyToMany(不用写中间表的Model,只 ...

  4. Codeforces 934.D A Determined Cleanup

    D. A Determined Cleanup time limit per test 1 second memory limit per test 256 megabytes input stand ...

  5. poj 3678 Katu Puzzle 2-SAT 建图入门

    Description Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a ...

  6. poj1679 次最小生成树 kruskal(暴力枚举)

    Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definit ...

  7. 向mysql中批量插入数据的性能分析

    MYSQL批量插入数据库实现语句性能分析 假定我们的表结构如下 代码如下   CREATE TABLE example (example_id INT NOT NULL,name VARCHAR( 5 ...

  8. Windows2008下RDP采用私有CA服务器证书搭建文档

    在中小型公司建立企业根证书颁发机构 (CA) http://www.microsoft.com/china/smb/issues/sgc/articles/build_ent_root_ca.mspx ...

  9. 非常好的Linux教程,让你的linux之路更通畅

    1  第1讲.Linux应用与发展(上) 2013-10-22 17:43 | 播放(46) | 评论(0) | 时长:51:38 2  第1讲.Linux应用与发展(下) 2013-10-22 17 ...

  10. switch case语句的用法

    Java语言 switch支持部分基本数据类型(primitive data types),如:byte.short.int.long.char:不支持boolean.float.double. 如图 ...