ElasticSearch:配置自定义分析器实现

时间:2012-07-16 13:51:46

标签: lucene elasticsearch jsm

目前,我正在评估基于lucene的传统分析器组件是否以及如何转移到弹性搜索(0.19.18)。由于遗留代码基于lucene,我将分析器包装在es-plugin中。分析仪的配置如下所示:

index.analysis.analyzer.myAnalyzer.type : myAnalyzer
index.analysis.analyzer.default.type: myAnalyzer
index.analysis.analyzer.default_index.type: myAnalyzer
index.analysis.analyzer.default_search.type: myAnalyzer

到目前为止一切顺利。

curl -XGET 'localhost:9200/_analyze' -d 'Some text'

将返回包含正确标记化文本的对象,但

curl -XGET 'localhost:9200/<name-of-my-index>/_analyze' -d 'Some text'

会返回一个文本,根本不会被标记化。显然,仅使用小写过滤器而不是myAnalyzer。索引中的对象未正确分析。

索引映射看起来像这样(从head-plugin输出):

mappings: {
item: {
    analyzer: myAnalyzer
    properties: {
        id: {
            type: string
        }
        itemnumber: {
            type: string
        }
        articletext: {
            analyzer: myAnalyzer
            type: string
        }
        sortvalue: {
            type: string
        }
        salesstatus: {
            format: dateOptionalTime
            type: date
        }
    }
}
}

由于我是ES的新手,我无法弄清楚,这种行为究竟是什么原因。有人有想法吗?

1 个答案:

答案 0 :(得分:2)

这是我如何在Elasticsearch中设置自定义默认分析器。

index:
  analysis:
    analyzer:
      default:
        filter: [lowercase]
        tokenizer: whitespace
        type: custom

像魅力一样工作。

相关问题