Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.94 KB | None | 0 0
  1. # Delete the `people` index
  2. DELETE /people
  3.  
  4. # Create the `people` index with proper settings
  5. PUT /people
  6. {
  7. "settings": {
  8. "analysis": {
  9. "filter": {
  10. "brazilian_stop": {
  11. "type": "stop",
  12. "stopwords": "_brazilian_"
  13. },
  14. "brazilian_stemmer": {
  15. "type": "stemmer",
  16. "language": "brazilian"
  17. }
  18. },
  19. "analyzer": {
  20. "brazilian": {
  21. "tokenizer": "standard",
  22. "filter": [
  23. "lowercase",
  24. "brazilian_stop",
  25. "brazilian_stemmer"
  26. ]
  27. }
  28. }
  29. }
  30. },
  31. "mappings": {
  32. "person": {
  33. "properties": {
  34. "name": {
  35. "type": "multi_field",
  36. "fields": {
  37. "name": {
  38. "type": "string",
  39. "analyzer":"brazilian"
  40. },
  41. "untouched": {
  42. "type": "string",
  43. "index" : "not_analyzed"
  44. }
  45. }
  46. },
  47. "tags": {
  48. "type": "string"
  49. },
  50. "emails":{
  51. "type": "multi_field",
  52. "fields": {
  53. "email": {
  54. "type": "string",
  55. "index" : "analyzed",
  56. "analyzer": "simple"
  57. },
  58. "untouched":{
  59. "type": "string",
  60. "index" : "not_analyzed"
  61. }
  62. }
  63. },
  64. "phones":{
  65. "type": "multi_field",
  66. "fields": {
  67. "phones": {
  68. "type": "string",
  69. "index" : "analyzed",
  70. "analyzer": "whitespace"
  71. },
  72. "untouched":{
  73. "type": "string",
  74. "index" : "not_analyzed"
  75. }
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82.  
  83. # Index some example docs
  84. PUT /people/person/_bulk
  85. {"index":{"_id":1}}
  86. {"name":"Luiz Freneda", "phones":["11 963427193", "(11) 96342-7193"], "emails":["lfreneda@gmail.com"], "tags":["developer", "elasticsearcher", "cto"]}
  87. {"index":{"_id":2}}
  88. {"name":"Eduardo Santos", "emails":["eduardoluizsantos@gmail.com"], "tags":["developer", "ceo", "show-man"]}
  89. {"index":{"_id":3}}
  90. {"name":"Joao Sem acento", "emails":["joaosemacento@hotmail.com"], "tags":["user"]}
  91. {"index":{"_id":4}}
  92. {"name":"João Com acento", "emails":["joaocomacento@yahoo.com"], "tags":["user"]}
  93.  
  94.  
  95. # Find people by name and tags
  96. GET /people/person/_search
  97. {
  98. "from":0,
  99. "size":10,
  100. "query":{
  101. "bool":{
  102. "should":[
  103. {
  104. "match":{
  105. "name":"Joao"
  106. }
  107. },
  108. {
  109. "regexp":{
  110. "name.untouched":"(.*)Jo[a|ã]o(.*)"
  111. }
  112. }
  113. ],
  114. "must":[
  115. {
  116. "match":{
  117. "tags":"user"
  118. }
  119. }
  120. ],
  121. "minimum_should_match":"100%"
  122. }
  123. },
  124. "highlight" : {
  125. "pre_tags" : ["<b>"],
  126. "post_tags" : ["</b>"],
  127. "fields" : {
  128. "name" : {
  129.  
  130. }
  131. }
  132. }
  133. }
  134.  
  135. # Find people by pretty much everything haha
  136. GET /people/person/_search
  137. {
  138. "from":0,
  139. "size":10,
  140. "query":{
  141. "bool":{
  142. "should":[
  143. {
  144. "match":{
  145. "name":"963427193"
  146. }
  147. },
  148. {
  149. "regexp":{
  150. "name.untouched":"(.*)963427193(.*)"
  151. }
  152. }
  153. ,
  154. {
  155. "regexp":{
  156. "emails.untouched":"(.*)963427193(.*)"
  157. }
  158. },
  159. {
  160. "regexp":{
  161. "phones.untouched":"(.*)963427193(.*)"
  162. }
  163. }
  164. ]
  165. }
  166. },
  167. "highlight" : {
  168. "pre_tags" : ["<b>"],
  169. "post_tags" : ["</b>"],
  170. "fields" : {
  171. "name" : {
  172.  
  173. },
  174. "email" : {
  175.  
  176. },
  177. "phones" : {
  178.  
  179. }
  180. }
  181. }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement