弹性搜索匹配与术语查询 [英] elasticsearch match vs term query

查看:111
本文介绍了弹性搜索匹配与术语查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用匹配查询搜索request.method:GET:

I use the match query search for "request.method": "GET":

    {
      "query": {
        "filtered": {
          "query": {
            "match": {
              "request.method": "GET"
            }
          },
          "filter": {
            "bool": {
              "must": [
...

如预期,Match查询可以得到结果,如下所示:

As expected, the Match query can get the results, as shown below:

但问题是使用条件查询,没有结果。

But the question is when using the Term query, there is no results.

更新查询以将匹配更改为期限,并保持其他部分保持不变:

Update the query to change the "match" to "term", and keep the other part remain the same:

{
  "query": {
    "filtered": {
      "query": {
        "term": {
          "request.method": "GET"
        }
      },
      "filter": {
        "bool": {
          "must": [
...

我认为术语查询是不分析版本的Match查询。如上图所示,至少有一个记录request.method等于GET。为什么上述Term查询没有结果?谢谢。

I think the Term query is the "not analyzed" version of the Match query. As shown in above picture, there is at least one record has "request.method" equal to "GET". Why there is no results for the above-mentioned Term query? Thank you.

推荐答案

假设您正在使用标准分析器 GET 成为 get 存储在索引中。源文件仍然具有原始的GET。

Assuming you are using the Standard Analyzer GET becomes get when stored in the index. The source document will still have the original "GET".

匹配查询将应用相同的标准分析器搜索项将因此匹配索引中存储的内容。 术语查询不会对搜索字词应用任何分析器,因此只会在反向索引中查找该确切术语。

The match query will apply the same standard analyzer to the search term and will therefore match what is stored in the index. The term query does not apply any analyzers to the search term, so will only look for that exact term in the inverted index.

要在示例中使用术语查询,请将大写GET更改为小写get或更改映射,以使request.method字段设置为 not_analyzed

To use the term query in your example, change the upper case "GET" to lower case "get" or change your mapping so the request.method field is set to not_analyzed.

这篇关于弹性搜索匹配与术语查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆