Reputation: 524
Firstly,I create an index:
PUT blog
Then,set mapping:
POST blog/article/_mapping
{
"article": {
"_all": {
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"term_vector": "no",
"store": "false"
}
}
}
Index some docs:
POST blog/article/1
{
"title":"java编程思想",
"content":"《Java编程思想》这本书赢得了全球程序员的广泛赞誉"
}
POST blog/article/2
{
"title":"手把手教你使用Git",
"content":"这是一个非常容易上手的GIt详细教程"
}
POST blog/article/3
{
"title":"java从入门到精通",
"content":"《java从入门到精通》非常适合java初学"
}
Search docs:
POST blog/_search
{
"query": {
"match": {
"title": "编程"
}
},
"highlight": {
"fields": {
"title": {
"pre_tags": "<strong>",
"post_tags": "</strong>"
}
}
}
}
Response:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.5649868,
"hits": [
{
"_index": "blog",
"_type": "article",
"_id": "1",
"_score": 0.5649868,
"_source": {
"title": "java编程思想",
"content": "《Java编程思想》这本书赢得了全球程序员的广泛赞誉"
},
"highlight": {
"title": [
"java<strong>编</strong><strong>程</strong>思想"
]
}
}
]
}
}
The IK analyzer does not work.I do not know what fields the index has in advance。How to set IK analyzer as the default analyzer of all index in Elasticsearch 5.1.1?
Upvotes: 1
Views: 633
Reputation: 26
Add following lines to the end of /etc/elasticsearch/elasticsearch.yml, to set ik as default analyzer:
index.analysis.analyzer.default.type: "ik"
index.analysis.analyzer.standard.type: "ik"
Upvotes: 1