【问题标题】:Elasticsearch Analyze API OddityElasticsearch 分析 API 异常
【发布时间】:2015-01-08 17:39:19
【问题描述】:

我的问题很简单。假设我在索引中有一个类型映射,如下所示:

"mappings" : {
  "post" : {
    "analyzer" : "my_custom_analyzer",
    "properties" : {
      "body" : {
        "type" : "string",
        "store" : true
      }
    }
  }
}

请注意,我将my_custom_analyzer 指定为该类型的分析器。当我在查询中没有指定分析器的情况下搜索正文字段时,I expect my_custom_analyzer to be used。但是,当我使用分析 API 查询字段时:

curl http://localhost:9200/myindex/_analyze?field=post.body&text=test

返回字符串的标准分析结果。当我指定分析器时,它可以工作:

curl http://localhost:9200/myindex/_analyze?analyzer=my_custom_analyzer&text=test

我的问题是:为什么我指定字段时,Analyze API 不使用默认类型分析器?

【问题讨论】:

    标签: search elasticsearch analysis


    【解决方案1】:

    分析器是每个字符串字段。 您不能将它应用于对象或嵌套对象,并希望该对象字段下的所有字段都将继承该分析器。 正确的做法如下——

    "mappings" : {
      "post" : {
        "properties" : {
          "body" : {
            "type" : "string",
            "analyzer" : "my_custom_analyzer",
            "store" : true
          }
        }
      }
    }
    

    分析器适用于分析器 API 的原因是您已经为该索引声明了分析器。

    如果要为特定对象下的所有字符串字段定义分析器,则需要在类型模板中提及。你可以在这里获得更多信息 - http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-root-object-type.html#_dynamic_templates

    【讨论】:

      猜你喜欢
      • 2016-11-21
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-14
      • 2020-12-03
      • 1970-01-01
      • 2019-01-28
      相关资源
      最近更新 更多