首页 文章

elasticsearch匹配vs术语查询

提问于
浏览
55

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

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

正如预期的那样,Match查询可以获得结果,如下所示:

enter image description here

但问题是在使用Term查询时,没有结果 .

更新查询以将“匹配”更改为“术语”,并保持其他部分保持不变:

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

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

enter image description here

1 回答

  • 70

    假设您使用的Standard Analyzer GET 在存储在索引中时变为 get . 源文档仍将具有原始"GET" .

    match 查询将相同的标准分析器应用于搜索项,因此将匹配索引中存储的内容 . term 查询不会将任何分析器应用于搜索项,因此只会在倒排索引中查找该确切项 .

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

相关问题