【问题标题】:Elasticsearch match_phrase for multiple fields多个字段的 Elasticsearch match_phrase
【发布时间】:2018-04-15 09:56:43
【问题描述】:

我是 Elasticsaerch 的新手,我现在正在苦苦挣扎。我正在尝试搜索在字段 eset 中有确切短语的所有数据。我的查询看起来像这样并且它有效:

{
   "query" : {
      "match_phrase" : {
         "eset": "Win32/Kryptik.DLT"
      }
   }
}

现在,我还需要多个字段来获得准确的值,例如在 eset 和 registries 字段中,所以理论上应该是这样的:

{
   "query" : {
      "match_phrase" : {
         "eset": "Win32/Kryptik.DLT"
      },
      "match_phrase" : {
         "registries": 3
      }
   }
}

但显然,您不能在 Elasticsearch 中执行此操作。匹配似乎不适用于多个字段。有什么办法吗?我需要保留大小写。只是确切的值。术语似乎不起作用,因为我的数据中使用了大写和小写以及斜线。

我尝试了所有我发现的东西,但没有任何效果。如果重要的话,我会使用 Python API 版本 6.1.1 和 Elasticsearch 版本 5.6.6。

【问题讨论】:

    标签: elasticsearch match match-phrase


    【解决方案1】:

    我想我自己想通了,解决方案是:

    {
      "query": {
        "bool": {
          "must": [
            { "match": { "eset":  { "query": "Win32/Kryptik.DLT", "type": "phrase" }}},
            { "match": { "registries":  { "query": 3, "type": "phrase" }}}
          ]
        }
      }
    }
    

    但我仍然对其他解决方案持开放态度,尤其是在 SLASHES 方面。

    【讨论】:

      【解决方案2】:

      如果您需要精确匹配输入字符串,请使用match_phrasematch_phrase 按给定顺序从输入搜索字符串中搜索单词,它们之间没有任何单词。match 对输入字符串中的单词进行模糊匹配。 参考:https://discuss.elastic.co/t/searching-fields-for-specific-values/64004/2

      {
        "query": {
          "bool": {
            "must": [
              { "match_phrase": { "eset":  { "query": "Win32/Kryptik.DLT", "type": "phrase" }}},
              { "match_phrase": { "registries":  { "query": 3, "type": "phrase" }}}
            ]
          }
        }
      }
      

      或者,如果您正在搜索精确值,可以使用term。但是,如果要搜索的精确值未知,请避免使用term。 来源:参考本页小节(avoid-term-query-text-fields)的34https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html#avoid-term-query-text-fields

      【讨论】:

        猜你喜欢
        • 2018-11-28
        • 1970-01-01
        • 2016-04-23
        • 1970-01-01
        • 2018-12-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多