elasticsearch的rest搜索--- 查询
目录: 一、针对这次装B 的解释
四、 查询
四、 查询
1. 查询的官网的文档

- took —— Elasticsearch执行这个搜索的耗时,以毫秒为单位- timed_out —— 指明这个搜索是否超时
- _shards —— 指出多少个分片被搜索了,同时也指出了成功/失败的被搜索的shards的数量
- hits —— 搜索结果
- hits.total —— 能够匹配我们查询标准的文档的总数目
- hits.hits —— 真正的搜索结果数据(默认只显示前10个文档)- _score和max_score —— 现在先忽略这些字段
"query":{
"match":{
"UserName":"BWH-PC"
}
}
{
"query": {
"match": {
"text": "quick fox"
}
}
}
相当于
{
"query": {
"bool": {
"should": [
{
"term": {
"text": "quick"
}
},
{
"term": {
"text": "fox"
}
}
]
}
}
}
{
"query": {
"multi_match": {
"query": "bbc0641345dd8224ce81bbc79218a16f",
"operator": "or",
"fields": [
"*.machine"
]
}
}
}
{
"bool": {
"must": {
"match": {
"title": "how to make millions"
}
},
"must_not": {
"match": {
"tag": "spam"
}
},
"should": [
{
"match": {
"tag": "starred"
}
},
{
"range": {
"date": {
"gte": "2014-01-01"
}
}
}
]
}
}
"term": {
"CapabilityDescriptions": "aa"
}
{
"query": {
"bool": {
"should": [
{
"constant_score": {
"query": {
"match": {
"description": "wifi"
}
}
}
},
{
"constant_score": {
"query": {
"match": {
"description": "garden"
}
}
}
},
{
"constant_score": {
"boost": {
"query": {
"match": {
"description": "pool"
}
}
}
}
}
]
}
}
}
missing相当于is null【没查到的是null】
{
"query": {
"filtered": {
"query": {
"match": {
"email": "business opportunity"
}
},
"filter": {
"term": {
"folder": "inbox"
}
}
}
}
}
{
"query": {
"filtered": {
"filter": {
"bool": {
"must": {
"term": {
"folder": "inbox"
}
},
"must_not": {
"query": {
"match": {
"email": "urgent business proposal"
}
}
}
}
}
}
}
}
"range": {
"price": {
"gt": 20,
"lt": 40
}
}
{
"query": {
"filtered": {
"filter": {
"range": {
"price": {
"gte": 20,
"lt": 40
}
}
}
}
}
}
{
"range": {
"timestamp": {
"gt": "2014-01-0100: 00: 00",
"lt": "2014-01-0700: 00: 00"
}
}
}
{
"range": {
"timestamp": {
"gt": "now-1h"
}
}
}
后置过滤--post_filter元素是一个顶层元素,只会对搜索结果进行过滤。警告:性能考量
只有当你需要对搜索结果和聚合使用不同的过滤方式时才考虑使用post_filter。有时一些用户会直接在常规搜索中使用post_filter。
不要这样做!post_filter会在查询之后才会被执行,因此会失去过滤在性能上帮助(比如缓存)。
post_filter应该只和聚合一起使用,并且仅当你使用了不同的过滤条件时。
{
"query": {
"query_string": {
"query": "*"
}
},
"post_filter": {
"bool": {
"should": {
"query": {
"bool": {
"should": [
{
"match": {
"machine": "bbc0641345dd8224ce81bbc79218a16f"
}
},
{
"match": {
"machine": "bbc0641345dd8224ce81bbc79218a16f"
}
}
]
}
}
}
}
}
}
当然,在里面的每一个should中,可以去做很多变形,但是should多个子类时,必须用[]
{
"query": {
"query_string": {
"query": "*"
}
},
"post_filter": {
"bool": {
"should": [
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "bbc0641345dd8224ce81bbc79218a16f",
"operator": "or",
"fields": [
"*.machine",
""
]
}
},
{
"multi_match": {
"query": "10.10.185.99",
"operator": "or",
"fields": [
"*.IPAddress",
""
]
}
}
]
}
}
},
{
"query": {
"bool": {
"must": [
{
"match": {
"machine": "bbc0641345dd8224ce81bbc79218a16f"
}
},
{
"match": {
"IPAddress": "10.10.11.11"
}
}
]
}
}
}
]
}
}
}


{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "*"
}
},
"filter": {
"bool": {
"should": {
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "a2",
"operator": "or",
"fields": [
"*.last"
]
}
},
{
"match": {
"last": "a2"
}
}
]
}
}
}
}
}
}
}
}

elasticsearch的rest搜索--- 查询的更多相关文章
- ElasticSearch High Level REST API【2】搜索查询
如下为一段带有分页的简单搜索查询示例 在search搜索中大部分的搜索条件添加都可通过设置SearchSourceBuilder来实现,然后将SearchSourceBuilder RestHighL ...
- ElasticSearch第四步-查询详解
ElasticSearch系列学习 ElasticSearch第一步-环境配置 ElasticSearch第二步-CRUD之Sense ElasticSearch第三步-中文分词 ElasticSea ...
- ElasticSearch中的简单查询
前言 最近修改项目,又看了下ElasticSearch中的搜索,所以简单整理一下其中的查询语句等.都是比较基础的.PS,好久没写博客了..大概就是因为懒吧.闲言少叙书归正传. 查询示例 http:// ...
- ElasticSearch(8)-分布式搜索
分布式搜索的执行方式 在继续之前,我们将绕道讲一下搜索是如何在分布式环境中执行的. 它比我们之前讲的基础的增删改查(create-read-update-delete ,CRUD)请求要复杂一些. 注 ...
- ElasticSearch(6)-结构化查询
引用:ElasticSearch权威指南 一.请求体查询 请求体查询 简单查询语句(lite)是一种有效的命令行_adhoc_查询.但是,如果你想要善用搜索,你必须使用请求体查询(request bo ...
- ElasticSearch改造研报查询实践
背景: 1,系统简介:通过人工解读研报然后获取并录入研报分类及摘要等信息,系统通过摘要等信息来获得该研报的URI 2,现有实现:老系统使用MSSQL存储摘要等信息,并将不同的关键字分解为不同字段来提供 ...
- elasticsearch基本概念与查询语法
序言 后面有大量类似于mysql的sum, group by查询 elk === elk总体架构 https://www.elastic.co/cn/products Beat 基于go语言写的轻量型 ...
- Graylog日志管理系统---搜索查询方法使用简介
Elasticsearch 是一个基于 Lucene 构建的开源.分布式.提供 RESTful 接口的全文搜索引擎 一.Search页面的各位置功能介绍: 1.日志搜索的时间范围 为了使用方便,预设有 ...
- 第三百六十五节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)的基本查询
第三百六十五节,Python分布式爬虫打造搜索引擎Scrapy精讲—elasticsearch(搜索引擎)的基本查询 1.elasticsearch(搜索引擎)的查询 elasticsearch是功能 ...
随机推荐
- LA3026 - Period(KMP)
For each prefix of a given string S with N characters (each character has an ASCII code between 97 a ...
- Android - 和其他APP交互 - 获得activity的返回值
启用另一个activity不一定是单向的.也可以启用另一个activity并且获得返回值.要获得返回值的话,调用startActivityForResult()(而不是startActivity()) ...
- QrcodeWithLogo
package com.qrcode; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Image; import ...
- 【原版的】PHP技术成长规划过程中猿人
PHP程序猿的技术成长规划 作者:黑夜路人(2014/10/15) 依照了解的非常多PHP/LNMP程序猿的发展轨迹.结合个人经验体会,抽象出非常多程序猿对未来的迷漫,特别对技术学习的盲目和慌乱.简单 ...
- StackExchange.Redis 使用 - 事件(五)
ConnectionMultiplexer 可以注册如下事件 ConfigurationChanged - 配置更改时 ConfigurationChangedBroadcast - 通过发布订阅更新 ...
- SIGPIPE并产生一个信号处理
阅读TCP某物,知道server并关闭sockfd当写两次,会产生SIGPIPE信号,假如不治疗,默认将挂起server 弄个小样本试验: #include <unistd.h> #inc ...
- 蓝牙4.0BLE cc2540 cc2541 ios OAD课程(空中固件升级)[原版的,多图]
蓝牙4.0BLE cc2540 cc2541 ios OAD课程(件) 为阿莫单片机论坛 www.AmoMcu.com 原创.仅仅公布于csdn博客, 如需转载,请注明出处,谢谢! ...
- net中使用ETW事件
在.net中使用ETW事件的方法 直到.net4.5,才有了比较便利的操作ETW的方法. 本文介绍的方法主要来源于Microsoft.Diagnostics.Tracing.TraceEvent官 ...
- Finding awesome developers in programming interviews(转)
英文原文:Finding awesome developers in programming interviews 我曾在一次面试中要求一个很有经验的嵌入式软件开发人员写出一个反转一段字符串并输出到屏 ...
- 关于int全区变量读写的原子性
关于int全区变量读写的原子性 关于int变量的读写是否原子性网上有非常多讨论,貌似不同平台不同,这里自己做实如今arm9平台測试.这里要注意原子性并不是指一条汇编才原子,实际上即使一次赋值编 ...