【问题标题】:Multi field analyzer not working as expected多场分析仪未按预期工作
【发布时间】:2015-12-12 04:27:29
【问题描述】:

我很困惑。我已将以下文档编入索引:

    POST test/topic
    {
      "title": "antiemetics"
    }

使用以下查询:

    {
        "query": { 
                        "query_string" : {
                            "fields" : ["title*"],
                            "default_operator": "AND", 
                            "query" :"anti emetics",
                            "use_dis_max" : true
                        }
                    },
                   "highlight" : {
                        "fields" : {
                            "*" : {
                                "fragment_size" : 200,
                                "pre_tags" : ["<mark>"],
                                "post_tags" : ["</mark>"]
                            }
                        }
                    }
    }

以及以下设置和映射:

     POST test{
           "settings":{
              "index":{
                 "number_of_shards":1,
                 "analysis":{
                    "analyzer":{
                       "merge":{
                          "type":"custom",
                          "tokenizer":"keyword",
                          "filter":[
                             "lowercase"
                          ],
                          "char_filter":[
                             "hyphen",
                             "space",
                             "html_strip"
                          ]
                       }
                    },
                    "char_filter":{
                       "hyphen":{
                          "type":"pattern_replace",
                          "pattern":"[-]",
                          "replacement":""
                       },
                       "space":{
                          "type":"pattern_replace",
                          "pattern":" ",
                          "replacement":""
                       }
                    }
                 }
              }
           },
           "mappings":{
              "topic":{
                 "properties":{
                    "title":{
                       "analyzer":"standard",
                       "search_analyzer":"standard",
                       "type":"string",
                       "fields":{
                          "specialised":{
                             "type":"string",
                             "index":"analyzed",
                             "analyzer":"standard",
                             "search_analyzer":"merge"
                          }
                       }
                    }
                 }
              }
           }
        }

我知道我使用多字段没有意义,因为我使用的是与标题相同的索引分析器,所以请忽略这一点,但是我对我对分析器的理解更感兴趣。我期待合并分析器将以下查询“antiemetics”更改为“antiemetics”,我希望应用了分析器的多字段设置与令牌“antiemetics”匹配,但我没有得到任何结果,即使我已经通过运行分析 API 测试了分析器正在从查询中删除空格。知道为什么吗?

【问题讨论】:

  • 你用的是什么版本的ES?

标签: elasticsearch


【解决方案1】:

这似乎适用于您的设置:

POST /test_index/_search
{
   "query": {
      "match": {
         "title.specialised": "anti emetics"
      }
   }
}

这是我设置的一些代码来玩它:

http://sense.qbox.io/gist/3ef6926644213cf7db568557a801fec6cb15eaf9

【讨论】:

  • 非常感谢,我希望使用 query_string 选项,但似乎由于它的工作方式,无法使用 search_analyzer。
猜你喜欢
  • 1970-01-01
  • 2018-08-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-14
  • 2016-05-20
相关资源
最近更新 更多