# 自定义分词器后，如何才能进行词干提取

**URL:** <https://discuss.elastic.co/t/topic/96573>\
**Category:** 中文提问与讨论\
**Created:** [August 10, 2017, 8:43am UTC](https://discuss.elastic.co/t/topic/96573 "2017-08-10T08:43:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DimonHo](https://avatars.discourse-cdn.com/v4/letter/d/9fc348/32.png) [@DimonHo](https://discuss.elastic.co/u/DimonHo)\
**Post date:** [August 10, 2017, 8:43am UTC](https://discuss.elastic.co/t/topic/96573/1 "2017-08-10T08:43:55Z")

</div>

假设我又这样一个索引：

```auto
PUT myindex
{
  "settings": {
    "analysis": {
      "analyzer": {
        "my_analyzer": {
          "tokenizer": "my_tokenizer",
          "filter": [
            "lowercase",
            "my_stemmer"
          ]
        }
      },
      "tokenizer": {
        "my_tokenizer": {
          "type": "pattern",
          "pattern": "[;]+"
        }
      },
      "filter": {
        "my_stemmer": {
          "type": "stemmer",
          "name": "english"
        }
      }
    }
  }
}

```

测试分析器：

```auto
GET /myindex/_analyze
{
  "analyzer": "my_analyzer",
  "text": "running dates;Sex health education;Perceptions towards Sexual Health Education"
}

```

需要将`running dates;Sex health education;Perceptions towards Sexual Health Education`按分号分词，然后在对其进行词形还原，预期结果应该是：

```auto
{
  "tokens": [
    {
      "token": "run date",
      "start_offset": 0,
      "end_offset": 13,
      "type": "word",
      "position": 0
    },
    {
      "token": "sex health educ",
      "start_offset": 14,
      "end_offset": 34,
      "type": "word",
      "position": 1
    },
    {
      "token": "percept toward sexual health educ",
      "start_offset": 35,
      "end_offset": 78,
      "type": "word",
      "position": 2
    }
  ]
}

```

然而实际结果却是这样：

```auto
{
  "tokens": [
    {
      "token": "running d",
      "start_offset": 0,
      "end_offset": 13,
      "type": "word",
      "position": 0
    },
    {
      "token": "sex health educ",
      "start_offset": 14,
      "end_offset": 34,
      "type": "word",
      "position": 1
    },
    {
      "token": "perceptions towards sexual health educ",
      "start_offset": 35,
      "end_offset": 78,
      "type": "word",
      "position": 2
    }
  ]
}

```

该如何实现我的需求？

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 7, 2017, 8:44am UTC](https://discuss.elastic.co/t/topic/96573/2 "2017-09-07T08:44:18Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
