0
我自己編寫了一個彈性分析器,但配置分析器時遇到了一些問題。Elasticsearch自定義分析器配置
我安裝了我的分析儀bin/plugin --url file:///[path_to_thulac.jar] --install analysis-smartcn
(基於smartcn,所以它的名字是smartcn)。並通過
curl -XPUT 'http://localhost:9200/about-index/_mapping/about' -d '
{
"properties": {
"searchable_text": {
"type": "string",
"analyzer": "smartcn"
}
}
}'
當我打電話curl -XGET 'localhost:9200/_analyze?analyzer=smartcn&pretty' -d '心理學概論'
,我得到了配置映射「心理學」 &「概論」,它是我想要的答案。
但是當我打電話搜索API
curl 'http://localhost:9200/title-index/_search?pretty=true' -d '{
"query" : {
"query_string": {
"default_field": "searchable_text",
"query": "心理",
"analyzer": "smartcn"
}
},
"script_fields": {
"terms" : {
"script": "doc[field].values",
"params": {
"field": "searchable_text"
}
}
}
}'
我terms: ["2014", "心理", "概論", "理學", "秋"]
我對這個問題很困惑,有人可以告訴我爲什麼?謝謝。
文檔的searchable_text字段是「心理學概論2014秋」,我認爲令牌是由分詞器分割後的結果。 – dreamszl 2015-03-20 05:27:27
@dreamszl看起來映射沒有正確應用,我已經更新了我的答案。 – imotov 2015-03-20 16:34:32