German analyzer

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

  1. PUT /german-index
  2. {
  3. "mappings": {
  4. "properties": {
  5. "content": {
  6. "type": "text",
  7. "analyzer": "german"
  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_german_analyzer
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "stem_exclusion_german_analyzer": {
  7. "type": "german",
  8. "stem_exclusion": ["Autorität", "Genehmigung"]
  9. }
  10. }
  11. }
  12. }
  13. }

copy

German analyzer internals

The german analyzer is built using the following components:

  • Tokenizer: standard

  • Token filters:

    • lowercase
    • stop (German)
    • keyword
    • normalization (German)
    • stemmer (German)

Custom German analyzer

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

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

copy

Generated tokens

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

  1. POST /german-index/_analyze
  2. {
  3. "field": "content",
  4. "text": "Die Studenten studieren an den deutschen Universitäten. Ihre Nummern sind 123456."
  5. }

copy

The response contains the generated tokens:

  1. {
  2. "tokens": [
  3. {
  4. "token": "student",
  5. "start_offset": 4,
  6. "end_offset": 13,
  7. "type": "<ALPHANUM>",
  8. "position": 1
  9. },
  10. {
  11. "token": "studi",
  12. "start_offset": 14,
  13. "end_offset": 23,
  14. "type": "<ALPHANUM>",
  15. "position": 2
  16. },
  17. {
  18. "token": "deutsch",
  19. "start_offset": 31,
  20. "end_offset": 40,
  21. "type": "<ALPHANUM>",
  22. "position": 5
  23. },
  24. {
  25. "token": "universitat",
  26. "start_offset": 41,
  27. "end_offset": 54,
  28. "type": "<ALPHANUM>",
  29. "position": 6
  30. },
  31. {
  32. "token": "numm",
  33. "start_offset": 61,
  34. "end_offset": 68,
  35. "type": "<ALPHANUM>",
  36. "position": 8
  37. },
  38. {
  39. "token": "123456",
  40. "start_offset": 74,
  41. "end_offset": 80,
  42. "type": "<NUM>",
  43. "position": 10
  44. }
  45. ]
  46. }