French analyzer

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

  1. PUT /french-index
  2. {
  3. "mappings": {
  4. "properties": {
  5. "content": {
  6. "type": "text",
  7. "analyzer": "french"
  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_french_analyzer
  2. {
  3. "settings": {
  4. "analysis": {
  5. "analyzer": {
  6. "stem_exclusion_french_analyzer": {
  7. "type": "french",
  8. "stem_exclusion": ["autorité", "acceptation"]
  9. }
  10. }
  11. }
  12. }
  13. }

copy

French analyzer internals

The french analyzer is built using the following components:

  • Tokenizer: standard

  • Token filters:

    • elision (French)
    • lowercase
    • stop (French)
    • keyword
    • stemmer (French)

Custom French analyzer

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

  1. PUT /french-index
  2. {
  3. "settings": {
  4. "analysis": {
  5. "filter": {
  6. "french_stop": {
  7. "type": "stop",
  8. "stopwords": "_french_"
  9. },
  10. "french_elision": {
  11. "type": "elision",
  12. "articles_case": true,
  13. "articles": [
  14. "l", "m", "t", "qu", "n", "s",
  15. "j", "d", "c", "jusqu", "quoiqu",
  16. "lorsqu", "puisqu"
  17. ]
  18. },
  19. "french_stemmer": {
  20. "type": "stemmer",
  21. "language": "light_french"
  22. },
  23. "french_keywords": {
  24. "type": "keyword_marker",
  25. "keywords": []
  26. }
  27. },
  28. "analyzer": {
  29. "french_analyzer": {
  30. "type": "custom",
  31. "tokenizer": "standard",
  32. "filter": [
  33. "french_elision",
  34. "lowercase",
  35. "french_stop",
  36. "french_keywords",
  37. "french_stemmer"
  38. ]
  39. }
  40. }
  41. }
  42. },
  43. "mappings": {
  44. "properties": {
  45. "content": {
  46. "type": "text",
  47. "analyzer": "french_analyzer"
  48. }
  49. }
  50. }
  51. }

copy

Generated tokens

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

  1. POST /french-index/_analyze
  2. {
  3. "field": "content",
  4. "text": "Les étudiants étudient à Paris et dans les universités françaises. Leurs numéros sont 123456."
  5. }

copy

The response contains the generated tokens:

  1. {
  2. "tokens": [
  3. {"token": "etudiant","start_offset": 4,"end_offset": 13,"type": "<ALPHANUM>","position": 1},
  4. {"token": "etudient","start_offset": 14,"end_offset": 22,"type": "<ALPHANUM>","position": 2},
  5. {"token": "pari","start_offset": 25,"end_offset": 30,"type": "<ALPHANUM>","position": 4},
  6. {"token": "universit","start_offset": 43,"end_offset": 54,"type": "<ALPHANUM>","position": 8},
  7. {"token": "francais","start_offset": 55,"end_offset": 65,"type": "<ALPHANUM>","position": 9},
  8. {"token": "numero","start_offset": 73,"end_offset": 80,"type": "<ALPHANUM>","position": 11},
  9. {"token": "123456","start_offset": 86,"end_offset": 92,"type": "<NUM>","position": 13}
  10. ]
  11. }