Query DSL - 查询和过滤上下文

Query and filter context

查询和过滤上下文

Relevance scores

相关性得分

By default, Elasticsearch sorts matching search results by relevance score, which measures how well each document matches a query.

默认情况下,Elasticsearch按相关性得分对匹配的搜索结果进行排序,该得分衡量每个文档与查询的匹配程度。

The relevance score is a positive floating point number, returned in the _score meta-field of the search API. The higher the _score, the more relevant the document. While each query type can calculate relevance scores differently, score calculation also depends on whether the query clause is run in a query or filter context.

相关性分数是一个正浮点数,在搜索 API 的meta-field(元字段)_score中返回 。_score越高,文档越相关。每种查询类型计算相关性得分可以不同,分数计算还取决于查询子句是运行在查询上下文中还是在过滤器上下文。

Query context

查询上下文

In the query context, a query clause answers the question “How well does this document match this query clause?” Besides deciding whether or not the document matches, the query clause also calculates a relevance score in the _score meta-field.

在查询上下文中,查询子句回答这样的问题“ 此文档与该查询子句的匹配程度如何?”除了确定文档是否匹配外,查询子句还计算meta-field(元字段)_score的相关性得分 。

Query context is in effect whenever a query clause is passed to a query parameter, such as the query parameter in the search API.

查询上下文在查询子句中通过query 参数设置,例如:

GET /_search
{
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

Filter context

过滤器上下文

In a filter context, a query clause answers the question “Does this document match this query clause?” The answer is a simple Yes or No — no scores are calculated. Filter context is mostly used for filtering structured data, e.g.

在过滤器上下文中,查询子句回答这样的问题“ *此文档是否与此查询子句匹配?*答案是简单的是或否-不计算分数。过滤器上下文主要用于过滤结构化数据,例如

  • Does this timestamp fall into the range 2015 to 2016?

  • Is the status field set to "published"?

  • timestamp是否属于2015年至2016年的范围?

  • *status 字段设置为"published"*吗?

Frequently used filters will be cached automatically by Elasticsearch, to speed up performance.

常用过滤器将由Elasticsearch自动缓存,以提高性能。

Filter context is in effect whenever a query clause is passed to a filter parameter, such as the filter or must_not parameters in the bool query, the filter parameter in the constant_score query, or the filter aggregation.

过滤器上下文在查询子句中通过filter 参数设置(例如 bool查询中的filter参数和must_not参数, constant_score中的filter参数,或者filter聚合)。

Example of query and filter contexts

查询和过滤器上下文示例

Below is an example of query clauses being used in query and filter context in the search API. This query will match documents where all of the following conditions are met:

以下是在searchAPI中使用查询上下文和过滤器上下文查询子句的示例。此查询将匹配满足以下所有条件的文档:

  • The title field contains the word search.

  • The content field contains the word elasticsearch.

  • The status field contains the exact word published.

  • The publish_date field contains a date from 1 Jan 2015 onwards.

  • title字段包含单词search

  • content字段包含单词elasticsearch

  • status字段包含确切的单词published

  • publish_date字段包含从2015年1月1日开始的日期。

GET /_search
{
  "query": { 
    "bool": { 
      "must": [
        { "match": { "title":   "Search"        }},
        { "match": { "content": "Elasticsearch" }}
      ],
      "filter": [ 
        { "term":  { "status": "published" }},
        { "range": { "publish_date": { "gte": "2015-01-01" }}}
      ]
    }
  }
}

Copy as cURLView in Console

The query parameter indicates query context.
The bool and two match clauses are used in query context, which means that they are used to score how well each document matches.
The filter parameter indicates filter context. Its term and range clauses are used in filter context. They will filter out documents which do not match, but they will not affect the score for matching documents.
query参数表示查询上下文。
must下的两个match子句用于查询上下文,它们被用来表示每个文档匹配程度的评分。
filter下的参数表示过滤器上下文。其termand range子句用于过滤器上下文。它们将过滤出不匹配的文档,但不会影响匹配文档的分数。

Scores calculated for queries in query context are represented as single precision floating point numbers; they have only 24 bits for significand’s precision. Score calculations that exceed the significand’s precision will be converted to floats with loss of precision.

在查询上下文中为查询计算的分数被表示为单精度浮点数;他们只有24位bits的有效数字的精度。超过有效位数精度的计算分数将转换为失去精度的浮点数。

Use query clauses in query context for conditions which should affect the score of matching documents (i.e. how well does the document match), and use all other query clauses in filter context.

在查询上下文中使用查询子句以应对可能影响匹配文档得分(即文档匹配程度)的条件,并在过滤器上下文中使用所有其他查询子句。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ELK是三个开源软件的缩写,分别表示:Elasticsearch , Logstash, Kibana , 它们都是开源软件。新增了一个FileBeat,它是一个轻量级的日志收集处理工具(Agent),Filebeat占用资源少,适合于在各个服务器上搜集日志后传输给Logstash,官方也推荐此工具。Elasticsearch是个开源分布式搜索引擎,提供搜集、分析、存储数据三大功能。它的特点有:分布式,零配置,自动发现,索引自动分片,索引副本机制,restful风格接口,多数据源,自动搜索负载等。Logstash 主要是用来日志的搜集、分析、过滤日志的工具,支持大量的数据获取方式。一般工作方式为c/s架构,client端安装在需要收集日志的主机上,server端负责将收到的各节点日志进行过滤、修改等操作在一并发往elasticsearch上去。Kibana 也是一个开源和免费的工具,Kibana可以为 Logstash 和 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助汇总、分析和搜索重要数据日志。该课程从ELK组件中的两大组件和常用的应用日志收集进行剖析讲解。(1)ElasticSearch:从单台的安装到集群的搭建、从基础的入门使用到高级的搜索和聚合都进行了较好的阐述。(2) Logstash:通过收集apache日志,使用grok插件和geoip插件先让学习人员对整体框架做到了了解于胸。然后再深入的对LogStash重要的知识点进行了剖析。(3)应用日志收集:对常见的Apache、Nginx、MySQL、Syslog进行日志收集和分析。虽说没有讲解太多,但是我想应该能做到让大家对应用日志收集了解的更加深入。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值