Elasticsearch analyzer配置

时间:2016-07-16 14:12:18

标签: elasticsearch elasticsearch-plugin

我想为Elasticsearch中的任何索引设置一个全局分析器。

这些行被添加到elasticsearch.yaml:

index.analysis.analyzer.ik.type: ik
index.analysis.analyzer.default.type: ik
index.analysis.analyzer.standard.type: ik

重新启动Elasticsearch后,这些行显示在http://localhost:9200/_nodes/settings

index: {
  analysis: {
    analyzer: {
      standard: {
        type: "ik"
      },
      default: {
        type: "ik"
      },
      ik: {
        type: "ik"
      }
    }
  }
}

然后我测试了url http://localhost:9200/_analyze?text=时间& analyzer = ik

{
  tokens: [
    {
       token: "时间",
       start_offset: 0,
       end_offset: 2,
       type: "CN_WORD",
       position: 0
    }
  ]
}

它显示IKAnalyzer已启用。但是,当涉及http://localhost:9200/_analyze?text=时间&analyzer=standardhttp://localhost:9200/_analyze?text=时间时,会返回“标准”分析器结果:

{
  tokens: [
    {
       token: "时",
       start_offset: 0,
       end_offset: 1,
       type: "<IDEOGRAPHIC>",
       position: 0
    },
    {
       token: "间",
       start_offset: 1,
       end_offset: 2,
       type: "<IDEOGRAPHIC>",
       position: 1
    }
  ]
}

那么,我该怎么办?

1 个答案:

答案 0 :(得分:1)

默认分析器设置会影响真实的索引文档,而不会影响您使用http://localhost:9200/_analyze执行的“测试”请求。尝试将少量文档添加到索引中,然后查看搜索是否按预期工作