Hindi analyzer

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

  1. PUT /hindi-index
  2. {
  3. "mappings": {
  4. "properties": {
  5. "content": {
  6. "type": "text",
  7. "analyzer": "hindi"
  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_hindi_analyzer
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "stem_exclusion_hindi_analyzer": {
  7. "type": "hindi",
  8. "stem_exclusion": ["अधिकार", "अनुमोदन"]
  9. }
  10. }
  11. }
  12. }
  13. }

copy

Hindi analyzer internals

The hindi analyzer is built using the following components:

  • Tokenizer: standard

  • Token filters:

    • lowercase
    • decimal_digit
    • keyword
    • normalization (indic)
    • normalization (Hindi)
    • stop (Hindi)
    • stemmer (Hindi)

Custom Hindi analyzer

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

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

copy

Generated tokens

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

  1. POST /hindi-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": 5,
  7. "type": "<ALPHANUM>",
  8. "position": 0
  9. },
  10. {
  11. "token": "भारतिय",
  12. "start_offset": 6,
  13. "end_offset": 12,
  14. "type": "<ALPHANUM>",
  15. "position": 1
  16. },
  17. {
  18. "token": "विशवविदयालय",
  19. "start_offset": 13,
  20. "end_offset": 28,
  21. "type": "<ALPHANUM>",
  22. "position": 2
  23. },
  24. {
  25. "token": "पढ",
  26. "start_offset": 33,
  27. "end_offset": 38,
  28. "type": "<ALPHANUM>",
  29. "position": 4
  30. },
  31. {
  32. "token": "नंबर",
  33. "start_offset": 49,
  34. "end_offset": 53,
  35. "type": "<ALPHANUM>",
  36. "position": 7
  37. },
  38. {
  39. "token": "123456",
  40. "start_offset": 54,
  41. "end_offset": 60,
  42. "type": "<NUM>",
  43. "position": 8
  44. }
  45. ]
  46. }