简体   繁体   English

在 ElasticSearch 中,有没有办法获取 ES 为 term 查询请求返回的每个匹配项的匹配项数?

[英]In ElasticSearch, is there a way to get the number of terms matched for each match returned by ES for a term query request?

For a given term query search request, will i be able to find the number terms matched for each of the value returned by ElasticSearch?对于给定的术语查询搜索请求,我能否找到与 ElasticSearch 返回的每个值匹配的术语数量?

If suppose i have a input as -如果假设我有一个输入 -

{
    "query": {
        "match" : {
            "message" : "this is a test"
        }
    }
}

and for this if suppose i get matched values as - 'this man' and 'this man test'.为此,如果假设我得到匹配的值 - 'this man' 和 'this man test'。

here the number of terms matched wrt the request for 'this man' is 1 and for 'this man test' is 2.此处与“this man”的请求匹配的术语数为 1“this man test”的请求数为2。

Is there a way to directly get this number in the response?有没有办法直接在响应中获取这个数字?

You can do a terms aggregation to count exact sentences :您可以进行术语聚合来计算准确的句子:

  "query": {
    "match": {
      "message": "this is a test"
    }
  },
  "aggs": {
    "genres": {
      "terms": {
        "field": "message.keyword"
      }
    }
  }

Note that will need a mapping with a text (for the match query) and a keyword (for the agg).请注意,这将需要一个带有文本(用于匹配查询)和一个关键字(用于 agg)的映射。 This is the default mapping in ElasticSearch.这是 ElasticSearch 中的默认映射。

Depends of your need Significant text aggregation may also interest you取决于您的需要重要的文本聚合也可能会让您感兴趣

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM