Russian analyzer

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

  1. PUT /russian-index
  2. {
  3. "mappings": {
  4. "properties": {
  5. "content": {
  6. "type": "text",
  7. "analyzer": "russian"
  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_russian_analyzer
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "stem_exclusion_russian_analyzer": {
  7. "type": "russian",
  8. "stem_exclusion": ["авторитет", "одобрение"]
  9. }
  10. }
  11. }
  12. }
  13. }

copy

Russian analyzer internals

The russian analyzer is built using the following components:

  • Tokenizer: standard

  • Token filters:

    • lowercase
    • stop (Russian)
    • keyword
    • stemmer (Russian)

Custom Russian analyzer

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

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

copy

Generated tokens

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

  1. POST /russian-index/_analyze
  2. {
  3. "field": "content",
  4. "text": "Студенты учатся в университетах России. Их номера 123456."
  5. }

copy

The response contains the generated tokens:

  1. {
  2. "tokens": [
  3. {
  4. "token": "студент",
  5. "start_offset": 0,
  6. "end_offset": 8,
  7. "type": "<ALPHANUM>",
  8. "position": 0
  9. },
  10. {
  11. "token": "учат",
  12. "start_offset": 9,
  13. "end_offset": 15,
  14. "type": "<ALPHANUM>",
  15. "position": 1
  16. },
  17. {
  18. "token": "университет",
  19. "start_offset": 18,
  20. "end_offset": 31,
  21. "type": "<ALPHANUM>",
  22. "position": 3
  23. },
  24. {
  25. "token": "росс",
  26. "start_offset": 32,
  27. "end_offset": 38,
  28. "type": "<ALPHANUM>",
  29. "position": 4
  30. },
  31. {
  32. "token": "номер",
  33. "start_offset": 43,
  34. "end_offset": 49,
  35. "type": "<ALPHANUM>",
  36. "position": 6
  37. },
  38. {
  39. "token": "123456",
  40. "start_offset": 50,
  41. "end_offset": 56,
  42. "type": "<NUM>",
  43. "position": 7
  44. }
  45. ]
  46. }