I have written a elastic analyzer by myself, but met some problem when configure the analyzer.
I installed my analyzer by bin/plugin --url file:///[path_to_thulac.jar] --install analysis-smartcn
(based on the smartcn, so its name is smartcn). And configure the mapping by
curl -XPUT 'http://localhost:9200/about-index/_mapping/about' -d '
{
"properties": {
"searchable_text": {
"type": "string",
"analyzer": "smartcn"
}
}
}'
When I call curl -XGET 'localhost:9200/_analyze?analyzer=smartcn&pretty' -d '心理学概论'
, I got '心理学' & '概论' and it's the answer I wanted.
But when I call the search 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"
}
}
}
}'
I got terms: ["2014", "心理", "概论", "理学", "秋"]
I'm so confused with the problem, can someone tell me why? Thank you.