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. transition transform animate的使用

    注:代码显示效果可以自行粘贴复制查看 transition(过渡),主要是关注property的变化主要有四个属性transition-property.transition-durantion.tr ...

  2. HDU2824 The Euler function

    Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Description The Eule ...

  3. ui_modules和ui_method

    ## 06ui.py #coding:utf-8 import tornado.httpserver import tornado.ioloop import tornado.options impo ...

  4. qfish/Bee-Xcode-Template

    https://github.com/qfish/Bee-Xcode-Template Bee-Xcode-Template Xcode Template for BeeFramework. You ...

  5. 【原创】Linux环境下的图形系统和AMD R600显卡编程(5)——AMD显卡显命令处理机制

    通常通过读写设备寄存器对设备进行编程,在X86系统上,有专门的IO指令进行编程,在其他诸如MIPS.SPARC这类系统上,通过将设备的寄存器映射到内存地址空间直接使用读写内存的方式对设备进行编程. R ...

  6. 几种常见的YUV格式--yuv422:yuv420【转】

    转自:http://blog.csdn.net/u012288815/article/details/51799477 关于yuv 格式 YUV 格式通常有两大类:打包(packed)格式和平面(pl ...

  7. (二十五)epoll深入理解续

    转自:http://blog.csdn.net/yusiguyuan/article/details/15027821 在Linux的网络编程中,很长的时间都在使用select来做事件触发.在linu ...

  8. 为什么js引入页面后不起作用?

    为什么js引入页面后不起作用? 例如常见的报错:Uncaught ReferenceError: $ is not defined. 可能出现这种情况的原因如下: 原因一: 引入js的位置不对,应在使 ...

  9. 阿里云服务器,tomcat启动,一直卡在At least one JAR was scanned for TLDs yet contained no TLDs就不动了

    项目在本地是可以成功运行的,网上看到一堆各式各样的解决办法感觉都不适合我,于是绝望的删webapps,重新上传,一直不行. 重复了第3次还是第4次,居然就好了,这是什么操作.

  10. Python的程序结构[1] -> 方法/Method[4] -> 魔术方法 __call__ / __str__ / __repr__

    __call__ 方法 __call__ 是当对象被调用时会调用的方法,允许一个对象(类的实例等)像函数一样被调用,也可以传入参数. 1 class Foo(): 2 def __init__(sel ...