configuring.asciidoc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. [[configuring-analyzers]]
  2. === Configuring built-in analyzers
  3. The built-in analyzers can be used directly without any configuration. Some
  4. of them, however, support configuration options to alter their behaviour. For
  5. instance, the <<analysis-standard-analyzer,`standard` analyzer>> can be configured
  6. to support a list of stop words:
  7. [source,js]
  8. --------------------------------
  9. PUT my_index
  10. {
  11. "settings": {
  12. "analysis": {
  13. "analyzer": {
  14. "std_english": { <1>
  15. "type": "standard",
  16. "stopwords": "_english_"
  17. }
  18. }
  19. }
  20. },
  21. "mappings": {
  22. "my_type": {
  23. "properties": {
  24. "my_text": {
  25. "type": "text",
  26. "analyzer": "standard", <2>
  27. "fields": {
  28. "english": {
  29. "type": "text",
  30. "analyzer": "std_english" <3>
  31. }
  32. }
  33. }
  34. }
  35. }
  36. }
  37. }
  38. GET _cluster/health?wait_for_status=yellow
  39. POST my_index/_analyze
  40. {
  41. "field": "my_text", <2>
  42. "text": "The old brown cow"
  43. }
  44. POST my_index/_analyze
  45. {
  46. "field": "my_text.english", <3>
  47. "text": "The old brown cow"
  48. }
  49. --------------------------------
  50. // CONSOLE
  51. <1> We define the `std_english` analyzer to be based on the `standard`
  52. analyzer, but configured to remove the pre-defined list of English stopwords.
  53. <2> The `my_text` field uses the `standard` analyzer directly, without
  54. any configuration. No stop words will be removed from this field.
  55. The resulting terms are: `[ the, old, brown, cow ]`
  56. <3> The `my_text.english` field uses the `std_english` analyzer, so
  57. English stop words will be removed. The resulting terms are:
  58. `[ old, brown, cow ]`
  59. /////////////////////
  60. [source,js]
  61. ----------------------------
  62. {
  63. "tokens": [
  64. {
  65. "token": "old",
  66. "start_offset": 4,
  67. "end_offset": 7,
  68. "type": "<ALPHANUM>",
  69. "position": 1
  70. },
  71. {
  72. "token": "brown",
  73. "start_offset": 8,
  74. "end_offset": 13,
  75. "type": "<ALPHANUM>",
  76. "position": 2
  77. },
  78. {
  79. "token": "cow",
  80. "start_offset": 14,
  81. "end_offset": 17,
  82. "type": "<ALPHANUM>",
  83. "position": 3
  84. }
  85. ]
  86. }
  87. ----------------------------
  88. // TESTRESPONSE
  89. /////////////////////