使用ElasticSearch查询

news2025/1/8 16:30:41

从一个query body开始

{
  "query": {
    "bool": {
      "disable_coord": true,
      "must": [
        {
          "match": {
            "enabled": "1"
          }
        },
        {
          "range": {
            "effectTime": {
              "lt": "2017-06-13 13:33:54"
            }
          }
        },
        {
          "range": {
            "expireTime": {
              "gt": "2017-06-13 13:33:54"
            }
          }
        }
      ],
      "should": [
        {
          "match": {
            "location": {
              "query": "北京",
              "boost": 2.7617
            }
          }
        }
      ]
    }
  },
  "size": 50
}
  • bool

A query that matches documents matching boolean combinations of other queries.

  • must

The clause must appear in matching documents and will contribute to the score.

  • should

The clause should appear in the matching document.

If the bool query is in a query context and has a must or filter clause then a document will match the bool query even if none of the should queries match. In this case these clauses are only used to influence the score.

If the bool query is a filter context or has neither must or filter then at least one of the should queries must match a document for it to match the bool query. This behavior may be explicitly controlled by settings the minimum_should_match parameter.

  • disable_coord

Suppose you have a should clause in which you have three queries now suppose one document matches first bool query then it will get some score on that but suppose this query do not exactly match second query but partially matches, now this document will be given some little bit score extra that means (first query match score + second query partial match score).

Now if u do not want this partial score to be given in your query then you should write “disable_coord”: true what it will do it will only give score to the document according to the exactly match query not on the partial match.

must, should

对于must和should,存储数据的形式是一样的。如果有多个查询条件,就放在数组中,如果只有一个查询条件,则可以直接赋值。

  • match
"must|should": [
    {
        "match": { "foo": "bar" }
    },
...

如果包含多个条件,不同条件之间可以使用 operator。Default or.

"must|should": [
    {
        "match": { "foo": {"query": "bar", "operator": "and"} }
    },
...
  • range
"must|should": [
    {
        "range": { "someTime": {"lt": "2017-06-13 13:33:54"} }
    },
...
  • term

The term query finds documents that contain the exact term specified in the inverted index.

  • terms

Filters documents that have fields that match any of the provided terms (not analyzed).

  • boost

A boost parameter can be specified to give this term query a higher relevance score than another query.

Term v.s. Match

  • term

Queries like the term or fuzzy queries are low-level queries that have no analysis phase. They operate on a single term. A term query for the term Foo looks for that exact term in the inverted index and calculates the TF/IDF relevance _score for each document that contains the term.

It is important to remember that the term query looks in the inverted index for the exact term only; it won’t match any variants like foo or FOO. It doesn’t matter how the term came to be in the index, just that it is. If you were to index [“Foo”,“Bar”] into an exact value not_analyzed field, or Foo Bar into an analyzed field with the whitespace analyzer, both would result in having the two terms Foo and Bar in the inverted index.

  • match

Queries like the match or query_string queries are high-level queries that understand the mapping of a field:

If you use them to query a date or integer field, they will treat the query string as a date or integer, respectively.
If you query an exact value (not_analyzed) string field, they will treat the whole query string as a single term.
But if you query a full-text (analyzed) field, they will first pass the query string through the appropriate analyzer to produce the list of terms to be queried.
Once the query has assembled a list of terms, it executes the appropriate low-level query for each of these terms, and then combines their results to produce the final relevance score for each document.

match 全文匹配, term 严格匹配。

其他

  • filter, must_not

这两个关键字和must, should在同一级别。

The filter clause must appear in matching documents. However unlike must the score of the query will be ignored. Filter clauses are executed in filter context, meaning that scoring is ignored and clauses are considered for caching.

The must_not clause must not appear in the matching documents. Clauses are executed in filter context meaning that scoring is ignored and clauses are considered for caching. Because scoring is ignored, a score of 0 for all documents is returned.

参考

Elasticsearch 权威指南(中文版)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2272697.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Cursor 实战技巧:好用的提示词插件Cursor Rules

你好啊,见字如面。感谢阅读,期待我们下一次的相遇。 最近在小红书发现了有人分享这款Cursor提示词的插件,下面给各位分享下使用教程。简单来说Cursor Rules就是可以为每一个我们自己的项目去配置一个系统级别的提示词,这样在我们…

Tomcat解析

架构图 核心功能 Tomcat是Apache开源的轻量级Java Servlet容器,其中一个Server(Tomcat实例)可以管理多个Service(服务),一个Service包含多个Connector和一个Engine,负责管理请求到应用的整个流…

List-顺序表--2

目录 1、ArrayList 2、ArrayList构造方法 3、ArrayList常见方法 4、ArrayList的遍历 5、ArrayList的扩容机制 6、ArrayList的具体使用 6.1、杨辉三角 6.2、简单的洗牌算法 1、ArrayList 在集合框架中,ArrayList 是一个普通的类,实现了 List 接口…

【C++】字符数|组的输出详解与拓展

博客主页: [小ᶻ☡꙳ᵃⁱᵍᶜ꙳] 本文专栏: C 文章目录 💯前言💯字符数组的输出:三种方法解析方法1:直接输出字符串代码示例解析与特点 方法2:使用while循环逐字符输出代码示例解析与特点 方法3&#x…

解决iNodeClient客户端出现查询SSL VPN网关参数失败的问题

一、问题: 使用iNodeClient连接VPN报错,校验网关、用户名、密码都没问题,仍然抱错查询SSL VPN网关参数失败,请检查网络配置或联系管理员。 二、解决方案: 2.1 方案一 重启iNodeAuthService服务 sudo /Library/Star…

数树数(中等难度)

题目: 解题代码: n,qmap(int,input().split())#分别输入层数和路径数量 for i in range(q):sinput()#输入“L”或“R”x1for j in s:if j "L":xx*2-1 #!!!规律else:xx*2print(x)

CAN201 Introduction to Networking(计算机网络)Pt.5 网络安全

文章目录 6. Network Security(网络安全)6.1 What is network security(什么是网络安全)6.2 Principles of cryptography(密码学的原则)6.2.1 Breaking an encryption scheme(破解加密方案&…

【ArcGIS Pro二次开发实例教程】(2):BSM字段赋值

一、简介 一般的数据库要素或表格都有一个BSM字段,用来标识唯一值。 此工具要实现的功能是:按一定的规律(前缀中间的填充数字OBJECT码)来给BSM赋值。 主要技术要点包括: 1、ProWindow的创建,Label,Comb…

ros2笔记-2.5.3 多线程与回调函数

本节体验下多线程。 python示例 在src/demo_python_pkg/demo_python_pkg/下新建文件,learn_thread.py import threading import requestsclass Download:def download(self,url,callback):print(f线程:{threading.get_ident()} 开始下载:{…

C语言练习:求数组的最大值与最小值

文章目录 1. 提出任务2. 完成任务2.1 方法一:通过返回结构体指针来间接返回结果2.1.1 编写程序,实现功能2.1.2 运行程序,查看结果 2.2 方法二:通过参数传递数组,并在函数中修改传入的参数2.2.1 编写程序,实…

conda安装及demo:SadTalker实现图片+音频生成高质量视频

1.安装conda 下载各个版本地址:https://repo.anaconda.com/archive/ win10版本: Anaconda3-2023.03-1-Windows-x86_64 linux版本: Anaconda3-2023.03-1-Linux-x86_64 Windows安装 环境变量 conda -V2.配置conda镜像源 安装pip conda…

【前端系列01】优化axios响应拦截器

文章目录 一、前言🚀🚀🚀二、axios响应拦截器:☀️☀️☀️2.1 为什么前端需要响应拦截器element ui的消息组件 一、前言🚀🚀🚀 ☀️ 回报不在行动之后,回报在行动之中。 这个系列可…

PingCAP 连续两年入选 Gartner 云数据库管理系统魔力象限“荣誉提及”

近日,全球 IT 市场研究和咨询公司 Gartner 发布最新报告《Magic Quadrant™ for Cloud Database Management Systems》(云数据库管理系统魔力象限),PingCAP 因其企业级开源分布式数据库 TiDB 在全球市场的表现,连续两年…

CSS——2.书写格式一

<!DOCTYPE html> <html><head><meta charset"UTF-8"><title></title></head><body><!--css书写中&#xff1a;--><!--1.css 由属性名:属性值构成--><!--style"color: red;font-size: 20px;&quo…

QT上实现SVM进行数据分类

针对不了解SVM的原理的同学强推下面这个课程&#xff1a; 6.机器学习课程&#xff08;六&#xff09;支持向量机&#xff08;线性模型&#xff09;问题_哔哩哔哩_bilibili 一、QT实现SVM的方法 1.调用SVM的C语言库&#xff1a;麻烦&#xff0c;要专门去找库&#xff0c;cmak…

idea( 2022.3.2)打包报错总结

一 报错 class lombok.javac.apt.LombokProcessor (in unnamed module 0x4fe64d23) cannot access class com.sun.tools.javac.processing.JavacProcessingEnvironment (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.processing …

极客说|微软 Phi 系列小模型和多模态小模型

作者&#xff1a;胡平 - 微软云人工智能高级专家 「极客说」 是一档专注 AI 时代开发者分享的专栏&#xff0c;我们邀请来自微软以及技术社区专家&#xff0c;带来最前沿的技术干货与实践经验。在这里&#xff0c;您将看到深度教程、最佳实践和创新解决方案。关注「极客说」&am…

解决 IntelliJ IDEA 中 Tomcat 日志乱码问题的详细指南

目录 前言1. 分析问题原因2. 解决方案 2.1 修改 IntelliJ IDEA 的 JVM 选项2.2 配置 Tomcat 实例的 VM 选项 2.2.1 设置 Tomcat 的 VM 选项2.2.2 添加环境变量 3. 进一步优化 3.1 修改 Tomcat 的 logging.properties3.2 修改操作系统默认编码 3.2.1 Windows 系统3.2.2 Linux …

某小程序sign签名参数逆向分析

文章目录 1. 写在前面2. 接口分析3. 分析还原 【&#x1f3e0;作者主页】&#xff1a;吴秋霖 【&#x1f4bc;作者介绍】&#xff1a;擅长爬虫与JS加密逆向分析&#xff01;Python领域优质创作者、CSDN博客专家、阿里云博客专家、华为云享专家。一路走来长期坚守并致力于Python…

医学图像分析工具02:3D Slicer || 医学影像可视化与分析工具 支持第三方插件

3D Slicer 是一款功能全面的开源医学影像分析软件&#xff0c;广泛应用于影像处理、三维建模、影像配准和手术规划等领域。它支持多种医学影像格式&#xff08;如 DICOM、NIfTI&#xff09;和丰富的插件扩展&#xff0c;是神经科学、放射学和生物医学研究中不可或缺的工具。 在…