【问题标题】:Elastic search phrase exact match without analysing弹性搜索词组完全匹配,无需分析
【发布时间】:2017-10-01 05:09:44
【问题描述】:

当前弹性映射:

"properties": {
"content": {
    "type": "text",
       "term_vector":"with_positions_offsets",
     "fields": {
         "keyword": {                
             "type": "keyword",
             "ignore_above": 256
         }
    },
     "analyzer": "russian"
   }        
}

字段“内容”包含网站爬取的结果,正是页面“正文”标签内容,从标签中剥离。 任务是实现对该字段的三种搜索。 1.所有指定的单词 2.任何指定的词 3.正好在正文中

对于 1 个案例 - match_phrase 对于 2 案例 - 匹配 对于 3 种情况 - 必须有 match_phrase 而不进行分析,因为使用“俄语”分析器会发现这个短语具有不同的结尾和变格

尝试了这个查询但没有运气:

"query": {
"bool": {
    "must": [
     {
      "match_phrase": {   
           "content":  {
               "query": "some search phraze",
       "analyzer": "keyword"
        }
       }
     }
  ]
}

【问题讨论】:

    标签: elasticsearch full-text-search


    【解决方案1】:

    自我回答

    This的回答对我帮助很大

    向属性添加额外字段“原始”解决了问题。

    "properties": {
        "content": {
            "type": "text",
            "term_vector":"with_positions_offsets",
            "fields": {
                "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                },
                "raw": {
                    "type": "text",
                    "index": "analyzed"
                }
            },
        "analyzer": "russian"
        }        
    }  
    

    搜索查询如下所示:

    "query": {
        "bool": {
            "must": [
                 {
                     "match_phrase": {   
                         "content.raw":  {
                              "query": "some search phraze",
                         }
                     }
                 }
             ]
        }
    

    【讨论】:

      【解决方案2】:

      对于exact 匹配查询使用Term Query。因此,您的查询应如下所示:

      GET _search
      {
        "query": {
          "term" : { "content.keyword" : "some search phraze" } 
        }
      }
      

      【讨论】:

      • 没有找到结果。命中 = 0
      • 你能提供一些示例文件吗?
      • 这是千字节的文本。不管是几百字还是几千字。
      • 你能用一些例子来说明你想要实现什么吗?
      猜你喜欢
      • 1970-01-01
      • 2015-08-02
      • 2019-02-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多