Elasticsearch match_phrase与类型短语的multi_match的执行方式相同吗?

时间:2015-05-14 13:21:28

标签: elasticsearch

我在将match_phrase查询转换为多个字段的multi_match查询时遇到了一些问题。我的原始查询:

{
  "from" : 0,
  "size" : 50,
  "query" : {
    "filtered" : {
      "query" : {
        "match_phrase" : {
          "metadata.description" : "Search Terms"
        }
      },
      "filter" : {
        "bool" : {
          "must" : [ {
            "terms" : {
              "collectionId" : [ "1", "2" ]
            }
          } ]
        }
      }
    }
  }
}

正确返回结果,但当我将match_phrase作为multi_match重写为针对多个字段运行时:

{
  "from" : 0,
  "size" : 50,
  "query" : {
    "filtered" : {
      "query" : {
        "multi_match" : {
          "query" : "Search Terms",
          "fields" : [ "metadata.description", "metadata.title" ],
          "type" : "phrase"
        }
      },
      "filter" : {
        "bool" : {
          "must" : [ {
            "terms" : {
              "collectionId" : [ "1", "2" ]
            }
          } ]
        }
      }
    }
  }
}

我没有得到任何结果。有什么明显的我在这里做错了吗?

编辑:

必须与过滤器有关,如

{
  "from" : 0,
  "size" : 50,
  "query" : {
    "match_phrase" : {
      "metadata.description" : "Search Terms"
    }
  }
}

{
  "from" : 0,
  "size" : 50,
  "query" : {
    "multi_match" : {
      "query" : "Search Terms",
      "fields" : [ "metadata.description", "metadata.title" ],
      "type" : "phrase"
    }
  }
}

均按预期执行。

1 个答案:

答案 0 :(得分:0)

我不确定为什么,但不是使用filtered查询,并在顶层应用过滤器

{
  "from" : 0,
  "size" : 50,
  "query" : {
    "multi_match" : {
      "query" : "Search Terms",
      "fields" : [ "metadata.description", "metadata.title" ],
      "type" : "phrase"
    }
  },
  "filter" : {
    "bool" : {
      "must" : [ {
        "terms" : {
          "collectionId" : [ "1", "2" ]
        }
      } ]
    }
  }
}

解决了这个问题。