Porter stem token filter

The porter_stem token filter reduces words to their base (or stem) form and removes common suffixes from words, which helps in matching similar words by their root. For example, the word running is stemmed to run. This token filter is primarily used for the English language and provides stemming based on the Porter stemming algorithm.

Example

The following example request creates a new index named my_stem_index and configures an analyzer with a porter_stem filter:

  1. PUT /my_stem_index
  2. {
  3. "settings": {
  4. "analysis": {
  5. "filter": {
  6. "my_porter_stem": {
  7. "type": "porter_stem"
  8. }
  9. },
  10. "analyzer": {
  11. "porter_analyzer": {
  12. "tokenizer": "standard",
  13. "filter": [
  14. "lowercase",
  15. "my_porter_stem"
  16. ]
  17. }
  18. }
  19. }
  20. }
  21. }

copy

Generated tokens

Use the following request to examine the tokens generated using the analyzer:

  1. POST /my_stem_index/_analyze
  2. {
  3. "text": "running runners ran",
  4. "analyzer": "porter_analyzer"
  5. }

copy

The response contains the generated tokens:

  1. {
  2. "tokens": [
  3. {
  4. "token": "run",
  5. "start_offset": 0,
  6. "end_offset": 7,
  7. "type": "<ALPHANUM>",
  8. "position": 0
  9. },
  10. {
  11. "token": "runner",
  12. "start_offset": 8,
  13. "end_offset": 15,
  14. "type": "<ALPHANUM>",
  15. "position": 1
  16. },
  17. {
  18. "token": "ran",
  19. "start_offset": 16,
  20. "end_offset": 19,
  21. "type": "<ALPHANUM>",
  22. "position": 2
  23. }
  24. ]
  25. }