Finnish analyzer

The built-in finnish analyzer can be applied to a text field using the following command:

  1. PUT /finnish-index
  2. {
  3. "mappings": {
  4. "properties": {
  5. "content": {
  6. "type": "text",
  7. "analyzer": "finnish"
  8. }
  9. }
  10. }
  11. }

copy

Stem exclusion

You can use stem_exclusion with this language analyzer using the following command:

  1. PUT index_with_stem_exclusion_finnish_analyzer
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "stem_exclusion_finnish_analyzer": {
  7. "type": "finnish",
  8. "stem_exclusion": ["valta", "hyväksyntä"]
  9. }
  10. }
  11. }
  12. }
  13. }

copy

Finnish analyzer internals

The finnish analyzer is built using the following components:

  • Tokenizer: standard

  • Token filters:

    • lowercase
    • stop (Finnish)
    • keyword
    • stemmer (Finnish)

Custom Finnish analyzer

You can create a custom Finnish analyzer using the following command:

  1. PUT /finnish-index
  2. {
  3. "settings": {
  4. "analysis": {
  5. "filter": {
  6. "finnish_stop": {
  7. "type": "stop",
  8. "stopwords": "_finnish_"
  9. },
  10. "finnish_stemmer": {
  11. "type": "stemmer",
  12. "language": "finnish"
  13. },
  14. "finnish_keywords": {
  15. "type": "keyword_marker",
  16. "keywords": ["Helsinki", "Suomi"]
  17. }
  18. },
  19. "analyzer": {
  20. "finnish_analyzer": {
  21. "type": "custom",
  22. "tokenizer": "standard",
  23. "filter": [
  24. "lowercase",
  25. "finnish_stop",
  26. "finnish_keywords",
  27. "finnish_stemmer"
  28. ]
  29. }
  30. }
  31. }
  32. },
  33. "mappings": {
  34. "properties": {
  35. "content": {
  36. "type": "text",
  37. "analyzer": "finnish_analyzer"
  38. }
  39. }
  40. }
  41. }

copy

Generated tokens

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

  1. POST /finnish-index/_analyze
  2. {
  3. "field": "content",
  4. "text": "Opiskelijat opiskelevat Helsingissä ja Suomen yliopistoissa. Heidän numeronsa ovat 123456."
  5. }

copy

The response contains the generated tokens:

  1. {
  2. "tokens": [
  3. {"token": "opiskelij","start_offset": 0,"end_offset": 11,"type": "<ALPHANUM>","position": 0},
  4. {"token": "opiskelev","start_offset": 12,"end_offset": 23,"type": "<ALPHANUM>","position": 1},
  5. {"token": "helsing","start_offset": 24,"end_offset": 35,"type": "<ALPHANUM>","position": 2},
  6. {"token": "suome","start_offset": 39,"end_offset": 45,"type": "<ALPHANUM>","position": 4},
  7. {"token": "yliopisto","start_offset": 46,"end_offset": 59,"type": "<ALPHANUM>","position": 5},
  8. {"token": "numero","start_offset": 68,"end_offset": 77,"type": "<ALPHANUM>","position": 7},
  9. {"token": "123456","start_offset": 83,"end_offset": 89,"type": "<NUM>","position": 9}
  10. ]
  11. }