Arabic analyzer

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

  1. PUT /arabic-index
  2. {
  3. "mappings": {
  4. "properties": {
  5. "content": {
  6. "type": "text",
  7. "analyzer": "arabic"
  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_arabic
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "stem_exclusion_arabic_analyzer":{
  7. "type":"arabic",
  8. "stem_exclusion":["تكنولوجيا","سلطة "]
  9. }
  10. }
  11. }
  12. }
  13. }

copy

Arabic analyzer internals

The arabic analyzer is built using the following components:

  • Tokenizer: standard

  • Token filters:

    • lowercase
    • decimal_digit
    • stop (Arabic)
    • normalization (Arabic)
    • keyword
    • stemmer (Arabic)

Custom Arabic analyzer

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

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

copy

Generated tokens

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

  1. POST /arabic-index/_analyze
  2. {
  3. "field": "content",
  4. "text": "الطلاب يدرسون في الجامعات العربية. أرقامهم ١٢٣٤٥٦."
  5. }

copy

The response contains the generated tokens:

  1. {
  2. "tokens": [
  3. {
  4. "token": "طلاب",
  5. "start_offset": 0,
  6. "end_offset": 6,
  7. "type": "<ALPHANUM>",
  8. "position": 0
  9. },
  10. {
  11. "token": "يدرس",
  12. "start_offset": 7,
  13. "end_offset": 13,
  14. "type": "<ALPHANUM>",
  15. "position": 1
  16. },
  17. {
  18. "token": "جامع",
  19. "start_offset": 17,
  20. "end_offset": 25,
  21. "type": "<ALPHANUM>",
  22. "position": 3
  23. },
  24. {
  25. "token": "عرب",
  26. "start_offset": 26,
  27. "end_offset": 33,
  28. "type": "<ALPHANUM>",
  29. "position": 4
  30. },
  31. {
  32. "token": "ارقامهم",
  33. "start_offset": 35,
  34. "end_offset": 42,
  35. "type": "<ALPHANUM>",
  36. "position": 5
  37. },
  38. {
  39. "token": "123456",
  40. "start_offset": 43,
  41. "end_offset": 49,
  42. "type": "<NUM>",
  43. "position": 6
  44. }
  45. ]
  46. }