simplepatternsplit-tokenizer.asciidoc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. [[analysis-simplepatternsplit-tokenizer]]
  2. === Simple pattern split tokenizer
  3. ++++
  4. <titleabbrev>Simple pattern split</titleabbrev>
  5. ++++
  6. The `simple_pattern_split` tokenizer uses a regular expression to split the
  7. input into terms at pattern matches. The set of regular expression features it
  8. supports is more limited than the <<analysis-pattern-tokenizer,`pattern`>>
  9. tokenizer, but the tokenization is generally faster.
  10. This tokenizer does not produce terms from the matches themselves. To produce
  11. terms from matches using patterns in the same restricted regular expression
  12. subset, see the <<analysis-simplepattern-tokenizer,`simple_pattern`>>
  13. tokenizer.
  14. This tokenizer uses {lucene-core-javadoc}/org/apache/lucene/util/automaton/RegExp.html[Lucene regular expressions].
  15. For an explanation of the supported features and syntax, see <<regexp-syntax,Regular Expression Syntax>>.
  16. The default pattern is the empty string, which produces one term containing the
  17. full input. This tokenizer should always be configured with a non-default
  18. pattern.
  19. [float]
  20. === Configuration
  21. The `simple_pattern_split` tokenizer accepts the following parameters:
  22. [horizontal]
  23. `pattern`::
  24. A {lucene-core-javadoc}/org/apache/lucene/util/automaton/RegExp.html[Lucene regular expression], defaults to the empty string.
  25. [float]
  26. === Example configuration
  27. This example configures the `simple_pattern_split` tokenizer to split the input
  28. text on underscores.
  29. [source,console]
  30. ----------------------------
  31. PUT my_index
  32. {
  33. "settings": {
  34. "analysis": {
  35. "analyzer": {
  36. "my_analyzer": {
  37. "tokenizer": "my_tokenizer"
  38. }
  39. },
  40. "tokenizer": {
  41. "my_tokenizer": {
  42. "type": "simple_pattern_split",
  43. "pattern": "_"
  44. }
  45. }
  46. }
  47. }
  48. }
  49. POST my_index/_analyze
  50. {
  51. "analyzer": "my_analyzer",
  52. "text": "an_underscored_phrase"
  53. }
  54. ----------------------------
  55. /////////////////////
  56. [source,console-result]
  57. ----------------------------
  58. {
  59. "tokens" : [
  60. {
  61. "token" : "an",
  62. "start_offset" : 0,
  63. "end_offset" : 2,
  64. "type" : "word",
  65. "position" : 0
  66. },
  67. {
  68. "token" : "underscored",
  69. "start_offset" : 3,
  70. "end_offset" : 14,
  71. "type" : "word",
  72. "position" : 1
  73. },
  74. {
  75. "token" : "phrase",
  76. "start_offset" : 15,
  77. "end_offset" : 21,
  78. "type" : "word",
  79. "position" : 2
  80. }
  81. ]
  82. }
  83. ----------------------------
  84. /////////////////////
  85. The above example produces these terms:
  86. [source,text]
  87. ---------------------------
  88. [ an, underscored, phrase ]
  89. ---------------------------