Turkish analyzer

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

  1. PUT /turkish-index
  2. {
  3. "mappings": {
  4. "properties": {
  5. "content": {
  6. "type": "text",
  7. "analyzer": "turkish"
  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_turkish_analyzer
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "stem_exclusion_turkish_analyzer": {
  7. "type": "turkish",
  8. "stem_exclusion": ["otorite", "onay"]
  9. }
  10. }
  11. }
  12. }
  13. }

copy

Turkish analyzer internals

The turkish analyzer is built using the following components:

  • Tokenizer: standard

  • Token filters:

    • apostrophe
    • lowercase (Turkish)
    • stop (Turkish)
    • keyword
    • stemmer (Turkish)

Custom Turkish analyzer

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

  1. PUT /turkish-index
  2. {
  3. "settings": {
  4. "analysis": {
  5. "filter": {
  6. "turkish_stop": {
  7. "type": "stop",
  8. "stopwords": "_turkish_"
  9. },
  10. "turkish_stemmer": {
  11. "type": "stemmer",
  12. "language": "turkish"
  13. },
  14. "turkish_lowercase": {
  15. "type": "lowercase",
  16. "language": "turkish"
  17. },
  18. "turkish_keywords": {
  19. "type": "keyword_marker",
  20. "keywords": []
  21. }
  22. },
  23. "analyzer": {
  24. "turkish_analyzer": {
  25. "type": "custom",
  26. "tokenizer": "standard",
  27. "filter": [
  28. "apostrophe",
  29. "turkish_lowercase",
  30. "turkish_stop",
  31. "turkish_keywords",
  32. "turkish_stemmer"
  33. ]
  34. }
  35. }
  36. }
  37. },
  38. "mappings": {
  39. "properties": {
  40. "content": {
  41. "type": "text",
  42. "analyzer": "turkish_analyzer"
  43. }
  44. }
  45. }
  46. }

copy

Generated tokens

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

  1. POST /turkish-index/_analyze
  2. {
  3. "field": "content",
  4. "text": "Öğrenciler Türk üniversitelerinde öğrenim görüyor. Numara 123456."
  5. }

copy

The response contains the generated tokens:

  1. {
  2. "tokens": [
  3. {"token": "öğrenci","start_offset": 0,"end_offset": 10,"type": "<ALPHANUM>","position": 0},
  4. {"token": "türk","start_offset": 11,"end_offset": 15,"type": "<ALPHANUM>","position": 1},
  5. {"token": "üniversite","start_offset": 16,"end_offset": 33,"type": "<ALPHANUM>","position": 2},
  6. {"token": "öğre","start_offset": 34,"end_offset": 41,"type": "<ALPHANUM>","position": 3},
  7. {"token": "görüyor","start_offset": 42,"end_offset": 49,"type": "<ALPHANUM>","position": 4},
  8. {"token": "numar","start_offset": 51,"end_offset": 57,"type": "<ALPHANUM>","position": 5},
  9. {"token": "123456","start_offset": 58,"end_offset": 64,"type": "<NUM>","position": 6}
  10. ]
  11. }