如何将IK分析器设置为Elasticsearch 5.1.1中所有索引的默认分析器

时间:2017-01-02 13:21:34

标签: elasticsearch

首先,我创建了一个索引:

PUT blog

然后,设置映射:

POST blog/article/_mapping
{
  "article": {
    "_all": {
      "analyzer": "ik_max_word",
      "search_analyzer": "ik_max_word",
      "term_vector": "no",
      "store": "false"
    }
  }
}

索引一些文档:

   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初学"
}

搜索文档:

POST blog/_search
{
  "query": {
    "match": {
      "title": "编程"
    }
  },
  "highlight": {
    "fields": {
      "title": {
        "pre_tags": "<strong>",
        "post_tags": "</strong>"
      }
    }
  }
}

响应:

{
  "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>思想"
          ]
        }
      }
    ]
  }
}

IK分析器不起作用。我不知道索引提前有哪些字段。如何将IK分析器设置为Elasticsearch 5.1.1中所有索引的默认分析器?

1 个答案:

答案 0 :(得分:1)

将以下行添加到/etc/elasticsearch/elasticsearch.yml的末尾,将ik设置为默认分析器:

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