1.空查询

GET /index_2014*/type1,type2/_search
{}
GET /_search
{
"from": ,
"size":
}

2.查询表达式

DSL只需将查询语句传递给 query 参数

GET /_search
{
"query": YOUR_QUERY_HERE
}

查询全部 match_all 跟空查询等价

GET /_search
{
"query": {
"match_all": {}
}
}

针对某个字段,结构

{
QUERY_NAME: {
FIELD_NAME: {
ARGUMENT: VALUE,
ARGUMENT: VALUE,...
}
}
}
GET /_search
{
"query": {
"match": {
"tweet": "elasticsearch"
}
}
}

3.查询与过滤

查询:一个评分的匹配,计算相似度

过滤:一个不评分的匹配,只有是或否。过滤的性能更好。

4.重要字段

match_all:匹配所有

{ "match_all": {}}

match:全文匹配或精确匹配

{ "match": { "tweet": "About Search" }}
{ "match": { "age": }}
{ "match": { "date": "2014-09-01" }}
{ "match": { "public": true }}
{ "match": { "tag": "full_text" }}

multi_match:在多个字段上执行相同的match查询

{
"multi_match": {
"query": "full text search",
"fields": [ "title", "body" ]
}
}

range:找出那些落在指定区间内的数字或者时间

{
"range": {
"age": {
"gte": ,
"lt":
}
}
}

term:用于精确值 匹配,这些精确值可能是数字、时间、布尔或者那些not_analyzed 的字符串

{ "term": { "age":               }}
{ "term": { "date": "2014-09-01" }}
{ "term": { "public": true }}
{ "term": { "tag": "full_text" }}

terms:和 term 查询一样,但它允许你指定多值进行匹配。如果这个字段包含了指定值中的任何一个值,那么这个文档满足条件

{ "terms": { "tag": [ "search", "full_text", "nosql" ] }}

exists:查找指定字段中有值的文档

{
"exists": {
"field": "title"
}
}

missing:查找指定字段中无值的文档

5.组合多查询

bool:将多查询组合在一起。它支持参数:

  must:文档 必须 匹配这些条件才能被包含进来。

  must_not:文档 必须不 匹配这些条件才能被包含进来。

  should:如果满足这些语句中的任意语句,将增加 _score ,否则,无任何影响。它们主要用于修正每个文档的相关性得分。

  filter:必须 匹配,但它以不评分、过滤模式来进行。这些语句对评分没有贡献,只是根据过滤标准来排除或包含文档。

{
"bool": {
"must": { "match": { "title": "how to make millions" }},
"must_not": { "match": { "tag": "spam" }},
"should": [
{ "match": { "tag": "starred" }}
],
"filter": {
"range": { "date": { "gte": "2014-01-01" }}
}
}
}
{
"bool": {
"must": { "match": { "title": "how to make millions" }},
"must_not": { "match": { "tag": "spam" }},
"should": [
{ "match": { "tag": "starred" }}
],
"filter": {
"bool": {
"must": [
{ "range": { "date": { "gte": "2014-01-01" }}},
{ "range": { "price": { "lte": 29.99 }}}
],
"must_not": [
{ "term": { "category": "ebooks" }}
]
}
}
}
}

constant_score查询:

它将一个不变的常量评分应用于所有匹配的文档。它被经常用于你只需要执行一个 filter 而没有其它查询(例如,评分查询)的情况下。可以使用它来取代只有 filter 语句的 bool 查询。

{
"constant_score": {
"filter": {
"term": { "category": "ebooks" }
}
}
}

6. 验证查询

_validate, explain:判断查询是否合法以及原因。

GET /gb/tweet/_validate/query?explain
{
"query": {
"tweet" : {
"match" : "really powerful"
}
}
}

【ES】学习3-请求体查询的更多相关文章

  1. 第2部分 Elasticsearch查询-请求体查询、排序

    一.请求体查询 请求体 search API, 之所以称之为请求体查询(Full-Body Search),因为大部分参数是通过http请求体而非查询字符串来传递的. 请求体查询:不仅可以处理自身的查 ...

  2. elasticsearch 基础 —— 请求体查询

    请求体查询 简易 查询 -query-string search- 对于用命令行进行即席查询(ad-hoc)是非常有用的. 然而,为了充分利用查询的强大功能,你应该使用 请求体 search API, ...

  3. elasticsearch 请求体查询方式整理

    空查询(empty search) —{}— 在功能上等价于使用 match_all 查询, 正如其名字一样,匹配所有文档: GET /_search { "query": { & ...

  4. ElasticSearch 5学习(10)——结构化查询(包括新特性)

    之前我们所有的查询都属于命令行查询,但是不利于复杂的查询,而且一般在项目开发中不使用命令行查询方式,只有在调试测试时使用简单命令行查询,但是,如果想要善用搜索,我们必须使用请求体查询(request ...

  5. elasticsearch(5) 请求体搜索

    上一篇提到的轻量搜索非常简单便捷,但是通过请求体查询可以更充分的利用查询的强大功能.因为_search api中大部分参数是通过HTTP请求体而非查询字符串来传递的. 一 空查询 对于空查询来说,最简 ...

  6. ElasticSearch权威指南学习(结构化查询)

    请求体查询 简单查询语句(lite)是一种有效的命令行adhoc查询.但是,如果你想要善用搜索,你必须使用请求体查询(request body search)API. 空查询 我们以最简单的 sear ...

  7. FastAPI 学习之路(九)请求体有多个参数如何处理?

    系列文章: FastAPI 学习之路(一)fastapi--高性能web开发框架 FastAPI 学习之路(二) FastAPI 学习之路(三) FastAPI 学习之路(四) FastAPI 学习之 ...

  8. FastAPI 学习之路(十)请求体的字段

    系列文章: FastAPI 学习之路(一)fastapi--高性能web开发框架 FastAPI 学习之路(二) FastAPI 学习之路(三) FastAPI 学习之路(四) FastAPI 学习之 ...

  9. FastAPI 学习之路(十一)请求体 - 嵌套模型

    系列文章: FastAPI 学习之路(一)fastapi--高性能web开发框架 FastAPI 学习之路(二) FastAPI 学习之路(三) FastAPI 学习之路(四) FastAPI 学习之 ...

随机推荐

  1. (大数 求余) Large Division Light OJ 1214

    Large Division Given two integers, a and b, you should check whether a is divisible by b or not. We ...

  2. jenkins master-slave配置

    如果要想自动化构建,需要slave主机能够从源码库上拉代码,并打包构建 选取指定的slave进行构建 jenkins + docker 实现slave的动态构建和销毁 https://www.cnbl ...

  3. Study 3 —— Python运算符

    参考资料:http://www.runoob.com/python/python-operators.html#ysf2 定义变量: a = 10, b = 20 算术运算符: 运算符   描述 实例 ...

  4. CentOS6.x网易163yum源配置

    一.备份原yum源 [root@yancy ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.$(d ...

  5. CodeForces - 455C Civilization (dfs+并查集)

    http://codeforces.com/problemset/problem/455/C 题意 n个结点的森林,初始有m条边,现在有两种操作,1.查询x所在联通块的最长路径并输出:2.将结点x和y ...

  6. indexOf与includes的比较

    indexOf和includes都代表检测数组或字符串中是否包含某一个元素 其中indexOf返回的是数值类型,而includes返回的是布尔类型 var ary = [,,]; console.lo ...

  7. Quartz.net创建windows服务

    序言 安装服务 sc create XXService binpath= "XXService.exe" start= auto sc description XXService ...

  8. myeclispe 一直运行debug问题

    window->preferences->Myeclipse->Servers->Tomcat 然后找到你的相应的Tomcat服务器的版本,选中然后展开其下面的子菜单会发现有个 ...

  9. JavaScript练习 - 模态对话框

    模态对话框练习 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  10. pandas 定位 loc,iloc,ix

    In [114]: df Out[114]: A B C D 2018-06-30 0.318501 0.613145 0.485612 0.918663 2018-07-31 0.614796 0. ...