configuring.asciidoc 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. POST my_index/_analyze
  39. {
  40. "field": "my_text", <2>
  41. "text": "The old brown cow"
  42. }
  43. POST my_index/_analyze
  44. {
  45. "field": "my_text.english", <3>
  46. "text": "The old brown cow"
  47. }
  48. --------------------------------
  49. // CONSOLE
  50. <1> We define the `std_english` analyzer to be based on the `standard`
  51. analyzer, but configured to remove the pre-defined list of English stopwords.
  52. <2> The `my_text` field uses the `standard` analyzer directly, without
  53. any configuration. No stop words will be removed from this field.
  54. The resulting terms are: `[ the, old, brown, cow ]`
  55. <3> The `my_text.english` field uses the `std_english` analyzer, so
  56. English stop words will be removed. The resulting terms are:
  57. `[ old, brown, cow ]`
  58. /////////////////////
  59. [source,js]
  60. ----------------------------
  61. {
  62. "tokens": [
  63. {
  64. "token": "old",
  65. "start_offset": 4,
  66. "end_offset": 7,
  67. "type": "<ALPHANUM>",
  68. "position": 1
  69. },
  70. {
  71. "token": "brown",
  72. "start_offset": 8,
  73. "end_offset": 13,
  74. "type": "<ALPHANUM>",
  75. "position": 2
  76. },
  77. {
  78. "token": "cow",
  79. "start_offset": 14,
  80. "end_offset": 17,
  81. "type": "<ALPHANUM>",
  82. "position": 3
  83. }
  84. ]
  85. }
  86. ----------------------------
  87. // TESTRESPONSE
  88. /////////////////////