单字段 模糊匹配查询与精准查询
postman请求

POST     127.0.0.1:9200/book/_search

请求json:

{
"query":{
"match":{
"name":"晓明9"
}
}
} 注:match 模糊查询的标识 :查询内容自动拆分成分词来查询
  若match 改为 match_phrase :精准查询 具体可以查看 http://www.cnblogs.com/liuxiaoming123/p/8119217.html
   响应结果: {
"took": 51,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0.5753642,
"hits": [
{
"_index": "book",
"_type": "novel",
"_id": "1",
"_score": 0.5753642,
"_source": {
"name": "晓明1",
"country": "china1",
"age": 26,
"date": "1992-08-08"
}
},
{
"_index": "book",
"_type": "novel",
"_id": "5",
"_score": 0.28363907,
"_source": {
"name": "晓明",
"country": "china",
"age": 26,
"date": "1992-08-08"
}
},
{
"_index": "book",
"_type": "novel",
"_id": "8",
"_score": 0.28363907,
"_source": {
"name": "晓明",
"country": "china",
"age": 26,
"date": "1992-08-08"
}
},
{
"_index": "book",
"_type": "novel",
"_id": "9",
"_score": 0.23911436,
"_source": {
"name": "晓明9",
"country": "china9",
"age": 26,
"date": "1992-08-08"
}
}
]
}
}

多字段 模糊匹配查询与精准查询
postman请求URL:

POST  127.0.0.1:9200/book/_search

请求json字符串:

{
"query":{
"multi_match":{
"query":"晓明china",
"fields":["name","country"]
}
}
} 注:multi_match为指定多字段匹配 响应结果: {
    "took": 42,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 4,
        "max_score": 0.5753642,
        "hits": [
            {
                "_index": "book",
                "_type": "novel",
                "_id": "1",
                "_score": 0.5753642,
                "_source": {
                    "name": "晓明1",
                    "country": "china1",
                    "age": 26,
                    "date": "1992-08-08"
                }
            },
            {
                "_index": "book",
                "_type": "novel",
                "_id": "5",
                "_score": 0.47000363,
                "_source": {
                    "name": "晓明",
                    "country": "china",
                    "age": 26,
                    "date": "1992-08-08"
                }
            },
            {
                "_index": "book",
                "_type": "novel",
                "_id": "8",
                "_score": 0.47000363,
                "_source": {
                    "name": "晓明",
                    "country": "china",
                    "age": 26,
                    "date": "1992-08-08"
                }
            },
            {
                "_index": "book",
                "_type": "novel",
                "_id": "9",
                "_score": 0.23911436,
                "_source": {
                    "name": "晓明9",
                    "country": "china9",
                    "age": 26,
                    "date": "1992-08-08"
                }
            }
        ]
    }
}

语法查询 
未指定字段:
postman请求:

POST 127.0.0.1:9200/book/_search

请求json字符串:

{
"query":{
"query_string":{
"query":"(ElasticSearch AND 入门) OR SpringBoot"
}
}
} 返回结果: {
"took": 21,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 2.634553,
"hits": [
{
"_index": "book",
"_type": "novel",
"_id": "9",
"_score": 2.634553,
"_source": {
"name": "ElasticSearch 入门",
"country": "china9",
"age": 26,
"date": "1992-08-08"
}
},
{
"_index": "book",
"_type": "novel",
"_id": "1",
"_score": 0.2876821,
"_source": {
"name": "SpringBoot",
"country": "china1",
"age": 26,
"date": "1992-08-08"
}
}
]
}
}

语法查询
 指定字段:

postman请求:

POST 127.0.0.1:9200/book/_search

请求json字符串:

{
"query":{
"query_string":{
"query":"SpringBoot OR 中国",
"fields":["name","country"]
}
}
} 响应结果: {
"took": 11,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.8630463,
"hits": [
{
"_index": "book",
"_type": "novel",
"_id": "1",
"_score": 0.8630463,
"_source": {
"name": "SpringBoot",
"country": "中国",
"age": 26,
"date": "1992-08-08"
}
}
]
}
}

(结构化数据的查询)

指定字段查询:(term)

postman请求:

POST   127.0.0.1:9200/book/_search

请求json字符串:

{
"query" :
{
"term" : {"name" : "springboot"}
}
} 响应结果: {
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.2876821,
"hits": [
{
"_index": "book",
"_type": "novel",
"_id": "1",
"_score": 0.2876821,
"_source": {
"name": "SpringBoot",
"country": "中国",
"age": 26,
"date": "1992-08-08"
}
}
]
}
}

注:若查询英文时 应全字母小写 精确查询

  若查询中文时 应按单个字来查询

范围查询:

注:json请求字符串中部分字段的含义

  range:范围关键字

  gte 大于等于

  lte  小于等于

  gt 大于

  lt 小于

  now 当前时间

postman请求:

127.0.0.1:9200/book/_search

请求json字符串:

{
"query" :
{
"range" : {
"date" : {
"gte":"2017-01-01",
"lte":"now"
}
}
}
} 响应结果: {
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "book",
"_type": "novel",
"_id": "9",
"_score": 1,
"_source": {
"name": "ElasticSearch 入门",
"country": "china9",
"age": 28,
"date": "2017-08-08"
}
}
]
}
}

Filter Context(对数据进行过滤)

postman请求:

POST  127.0.0.1:9200/book/_search

请求json字符串:

{
"query" : {
"bool" : {
"filter" : {
"term":{
"age":20
}
}
}
}
} 响应结果: {
"took": 24,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0,
"hits": [
{
"_index": "book",
"_type": "novel",
"_id": "1",
"_score": 0,
"_source": {
"name": "SpringBoot",
"country": "中国",
"age": 20,
"date": "1992-08-08"
}
}
]
}
}

注: boost 固定响应结果分数的值

postman请求:

POST 127.0.0.1:9200/_search

请求json字符串:

{
"query" : {
"constant_score" : {
"filter" : {
"match":{
"name":"晓明"
}
},
"boost":2
}
}
} 响应结果: {
"took": 11,
"timed_out": false,
"_shards": {
"total": 8,
"successful": 8,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 2,
"hits": [
{
"_index": "book",
"_type": "novel",
"_id": "5",
"_score": 2,
"_source": {
"name": "晓明",
"country": "china",
"age": 26,
"date": "1992-08-08"
}
},
{
"_index": "book",
"_type": "novel",
"_id": "8",
"_score": 2,
"_source": {
"name": "晓明8",
"country": "china",
"age": 26,
"date": "1992-08-08"
}
}
]
}
}

should关键词:或的关系

若should改为must 关键词则表示 和的关系

postman请求:

POST 127.0.0.1:9200/_search

请求json字符串:
    1.shuld:
{
"query" : {
"bool" : {
"should" : [
{
"match":{"name":"springboot"}
},
{
"match":{"country":"中国"}
}
]
}
}
}

 2.must:
{
"query" : {
"bool" : {
"must" : [
{
"match":{"name":"springboot"}
},
{
"match":{"country":"中国"}
}
]
}
}
}

3.must filter:
{
    "query" : {
            "bool" : {
                "must" : [
                            {
                                "match":{"name":"springboot"}
                            },
                            {
                                "match":{"country":"中国"}
                            }
                            ],
                   "filter":[
                            {
                                "term":{
                                    "age":20
                                }
                            }    
                            ]
                        }
              }
}

4.must_not:
{
    "query" : {
            "bool" : {
                "must_not" : {
                                "term":{"age":20}
                             }
                      }
               }
}

ElasticSearch入门3: 高级查询的更多相关文章

  1. Elasticsearch入门,看这一篇就够了

    目录 前言 可视化工具 kibana kibana 的安装 kibana 配置 kibana 的启动 Elasticsearch 入门操作 操作 index 创建 index 索引别名有什么用 删除索 ...

  2. ElasticSearch高级查询

    ElasticSearch高级查询 https://www.imooc.com/video/15759/0 ElasticSearch查询 1,子条件查询:特定字段查询所指特定值 1.1query c ...

  3. elasticsearch 高级查询

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

  4. ElasticSearch入门 第九篇:实现正则表达式查询的思路

    这是ElasticSearch 2.4 版本系列的第九篇: ElasticSearch入门 第一篇:Windows下安装ElasticSearch ElasticSearch入门 第二篇:集群配置 E ...

  5. ElasticSearch入门 第五篇:使用C#查询文档

    这是ElasticSearch 2.4 版本系列的第五篇: ElasticSearch入门 第一篇:Windows下安装ElasticSearch ElasticSearch入门 第二篇:集群配置 E ...

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

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

  7. Elasticsearch入门教程(六):Elasticsearch查询(二)

    原文:Elasticsearch入门教程(六):Elasticsearch查询(二) 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:h ...

  8. Elasticsearch入门教程(五):Elasticsearch查询(一)

    原文:Elasticsearch入门教程(五):Elasticsearch查询(一) 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:h ...

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

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

随机推荐

  1. es6 字符串方法

    1.字符串的新方法  includes() 包含属性 startsWith() 头部开始是否包含 endWith() 字符串是否在尾部   ========三个返回值都为布尔值  第二参数为数字  e ...

  2. HDU 5656 CA Loves GCD (容斥)

    题意:给定一个数组,每次他会从中选出若干个(至少一个数),求出所有数的GCD然后放回去,为了使自己不会无聊,会把每种不同的选法都选一遍,想知道他得到的所有GCD的和是多少. 析:枚举gcd,然后求每个 ...

  3. 容器,表格 ,div,元素可左右拖动,滚动 css

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  4. JavaBase

    第一章: Java之父:詹姆斯.高斯林:1995年5月推出Java: java分为  java se : 基础版本(标准版) Java  EE  : 企业级开发   ME:嵌入式开发(已被安卓替代) ...

  5. Kafka C++客户端库librdkafka笔记

    目录 目录 1 1. 前言 2 2. 缩略语 2 3. 配置和主题 3 3.1. 配置和主题结构 3 3.1.1. Conf 3 3.1.2. ConfImpl 3 3.1.3. Topic 3 3. ...

  6. 1.9yield方法

    yield()方法的作用放弃当前的cpu资源,将他让给其他的任务去占用cpu的执行时间,但放弃的时间不确定,有可能刚放弃,马上又获得cpu时间片 测试 package com.cky.thread; ...

  7. window下切换python

    自己的win10装了2.7和3.6版本的python.本不想装2.7的,但node.js的C++的编译居然用到2.X的python,没法子就装了2.7.那怎么切换呢? 为了方便使用,我在系统的path ...

  8. Qt_MainWindow简介

    QMainWindow 是Qt框架带来的一个预定义好的主窗口类.按照建立HelloWorld程序建立工程,直接运行,或有一个空窗口. main().cpp #include "mainwin ...

  9. linux ping命令

    Linux系统的ping命令是常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着”.不能打开网页时会说“你先ping网关地址192.168.1.1试试”. ...

  10. 如何对CentOS FTP服务配置

    根据很多人对CentOS FTP服务的不解,我觉得应该对CentOS FTP服务做出一定的解释. 1.安装 一般在CentOS上都自动安装了vsftd,若没有安装则可以使用以下步骤进行安装yum -y ...