Norwegian analyzer

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

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

copy

Norwegian analyzer internals

The norwegian analyzer is built using the following components:

  • Tokenizer: standard

  • Token filters:

    • lowercase
    • stop (Norwegian)
    • keyword
    • stemmer (Norwegian)

Custom Norwegian analyzer

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

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

copy

Generated tokens

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

  1. POST /norwegian-index/_analyze
  2. {
  3. "field": "content",
  4. "text": "Studentene studerer ved norske universiteter. Deres nummer er 123456."
  5. }

copy

The response contains the generated tokens:

  1. {
  2. "tokens": [
  3. {"token": "student","start_offset": 0,"end_offset": 10,"type": "<ALPHANUM>","position": 0},
  4. {"token": "studer","start_offset": 11,"end_offset": 19,"type": "<ALPHANUM>","position": 1},
  5. {"token": "norsk","start_offset": 24,"end_offset": 30,"type": "<ALPHANUM>","position": 3},
  6. {"token": "universitet","start_offset": 31,"end_offset": 44,"type": "<ALPHANUM>","position": 4},
  7. {"token": "numm","start_offset": 52,"end_offset": 58,"type": "<ALPHANUM>","position": 6},
  8. {"token": "123456","start_offset": 62,"end_offset": 68,"type": "<NUM>","position": 8}
  9. ]
  10. }