Spanish analyzer

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

  1. PUT /spanish-index
  2. {
  3. "mappings": {
  4. "properties": {
  5. "content": {
  6. "type": "text",
  7. "analyzer": "spanish"
  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_spanish_analyzer
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "stem_exclusion_spanish_analyzer": {
  7. "type": "spanish",
  8. "stem_exclusion": ["autoridad", "aprobación"]
  9. }
  10. }
  11. }
  12. }
  13. }

copy

Spanish analyzer internals

The spanish analyzer is built using the following components:

  • Tokenizer: standard

  • Token filters:

    • lowercase
    • stop (Spanish)
    • keyword
    • stemmer (Spanish)

Custom Spanish analyzer

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

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

copy

Generated tokens

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

  1. POST /spanish-index/_analyze
  2. {
  3. "field": "content",
  4. "text": "Los estudiantes estudian en universidades españolas. Sus números son 123456."
  5. }

copy

The response contains the generated tokens:

  1. {
  2. "tokens": [
  3. {
  4. "token": "estudiant",
  5. "start_offset": 4,
  6. "end_offset": 15,
  7. "type": "<ALPHANUM>",
  8. "position": 1
  9. },
  10. {
  11. "token": "estudian",
  12. "start_offset": 16,
  13. "end_offset": 24,
  14. "type": "<ALPHANUM>",
  15. "position": 2
  16. },
  17. {
  18. "token": "universidad",
  19. "start_offset": 28,
  20. "end_offset": 41,
  21. "type": "<ALPHANUM>",
  22. "position": 4
  23. },
  24. {
  25. "token": "español",
  26. "start_offset": 42,
  27. "end_offset": 51,
  28. "type": "<ALPHANUM>",
  29. "position": 5
  30. },
  31. {
  32. "token": "numer",
  33. "start_offset": 57,
  34. "end_offset": 64,
  35. "type": "<ALPHANUM>",
  36. "position": 7
  37. },
  38. {
  39. "token": "123456",
  40. "start_offset": 69,
  41. "end_offset": 75,
  42. "type": "<NUM>",
  43. "position": 9
  44. }
  45. ]
  46. }