Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.82 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. "_routing": {
  34. "required": true,
  35. "path": "accountId"
  36. },
  37. "properties": {
  38. "accountId": {
  39. "type": "string",
  40. "index" : "not_analyzed"
  41. },
  42. "firstName": {
  43. "type": "multi_field",
  44. "fields": {
  45. "firstName": {
  46. "type": "string",
  47. "analyzer":"brazilian"
  48. },
  49. "untouched": {
  50. "type": "string",
  51. "index" : "not_analyzed"
  52. }
  53. }
  54. },
  55. "lastName": {
  56. "type": "multi_field",
  57. "fields": {
  58. "lastName": {
  59. "type": "string",
  60. "analyzer":"brazilian"
  61. },
  62. "untouched": {
  63. "type": "string",
  64. "index" : "not_analyzed"
  65. }
  66. }
  67. },
  68. "tags": {
  69. "type": "string"
  70. },
  71. "emails":{
  72. "type": "multi_field",
  73. "fields": {
  74. "email": {
  75. "type": "string",
  76. "index" : "analyzed",
  77. "analyzer": "simple"
  78. },
  79. "untouched":{
  80. "type": "string",
  81. "index" : "not_analyzed"
  82. }
  83. }
  84. },
  85. "phones":{
  86. "type": "multi_field",
  87. "fields": {
  88. "phones": {
  89. "type": "string",
  90. "index" : "analyzed",
  91. "analyzer": "whitespace"
  92. },
  93. "untouched":{
  94. "type": "string",
  95. "index" : "not_analyzed"
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }
  102. }
  103.  
  104. # Index some example docs
  105. PUT /people/person/_bulk
  106. {"index":{"_id":1}}
  107. {"firstName":"Luiz", "lastName": "Freneda", "phones":["(11) 96342-7193"], "emails":["l.freneda@gmail.com"], "tags":["developer", "elasticsearcher", "cto"]}
  108. {"index":{"_id":2}}
  109. {"firstName":"Eduardo", "lastName": "Santos", "emails":["eduardoluizsantos@gmail.com"], "tags":["developer", "ceo", "show-man"]}
  110. {"index":{"_id":3}}
  111. {"firstName":"Joao", "lastName": "Sem acento", "emails":["joaosemacento@hotmail.com"], "tags":["user"]}
  112. {"index":{"_id":4}}
  113. {"firstName":"João", "lastName": "Com acento", "emails":["joaocomacento@yahoo.com"], "tags":["user"]}
  114. }
  115.  
  116. GET /people/person/_search
  117. {
  118. "from": 0,
  119. "size": 10,
  120. "highlight": {
  121. "pre_tags": [
  122. "<b>"
  123. ],
  124. "post_tags": [
  125. "</b>"
  126. ],
  127. "fields": {
  128. "firstName": {},
  129. "lastName": {},
  130. "emails": {},
  131. "phones": {}
  132. }
  133. },
  134. "query": {
  135. "bool":{
  136. "should":[
  137. { "match":{ "firstName":"Luciano" } },
  138. { "regexp":{ "firstName.untouched":"(.*)Luci[a|ã|á|à]n[o|ó|õ](.*)" } },
  139. { "match":{ "lastName":"Luciano" } },
  140. { "regexp":{ "lastName.untouched":"(.*)Luci[a|ã|á|à]n[o|ó|õ](.*)" } },
  141. { "regexp":{ "emails.untouched":"(.*)Luciano(.*)" } },
  142. { "regexp":{ "phones.untouched":"(.*)00000000000(.*)" } }
  143. ]
  144. ,"must":[ { "terms":{ "tags":["vip","carlos"] } } ], "minimum_should_match":"17%"}
  145. }
  146. }
  147.  
  148. # Find people by name and tags
  149. GET /people/person/_search
  150. {
  151. "from":0,
  152. "size":10,
  153. "query":{
  154. "bool":{
  155. "should":[
  156. {
  157. "match":{
  158. "firstName":"Luciano"
  159. }
  160. },
  161. {
  162. "match":{
  163. "lastName":"Luciano"
  164. }
  165. },
  166. {
  167. "regexp":{
  168. "firstName.untouched":"(.*)Luciano(.*)"
  169. }
  170. },
  171. {
  172. "regexp":{
  173. "lastName.untouched":"(.*)Luciano(.*)"
  174. }
  175. }
  176. ,
  177. {
  178. "regexp":{
  179. "emails.untouched":"(.*)Luciano(.*)"
  180. }
  181. },
  182. {
  183. "regexp":{
  184. "phones.untouched":"(.*)Luciano(.*)"
  185. }
  186. }
  187. ],
  188. "must":[
  189. {
  190. "terms":{
  191. "tags":["vip","carlos"]
  192. }
  193. }
  194. ],
  195. "minimum_should_match":"17%"
  196. }
  197. },
  198. "highlight" : {
  199. "pre_tags" : ["<b>"],
  200. "post_tags" : ["</b>"],
  201. "fields" : {
  202. "name" : {
  203.  
  204. }
  205. }
  206. }
  207. }
  208.  
  209. GET /people/person/_search
  210. {
  211. "from": 0,
  212. "size": 15,
  213. "highlight": {
  214. "pre_tags": [
  215. "<b>"
  216. ],
  217. "post_tags": [
  218. "</b>"
  219. ],
  220. "fields": {
  221. "name": {},
  222. "emails": {},
  223. "phones": {}
  224. }
  225. },
  226. "query": {
  227. "bool": {
  228. "should": [
  229. {
  230. "match": {
  231. "name": {
  232. "query": "Joao"
  233. }
  234. }
  235. },
  236. {
  237. "regexp": {
  238. "name.untouched": {
  239. "value": "(.*)Joao(.*)"
  240. }
  241. }
  242. },
  243. {
  244. "regexp": {
  245. "emails.untouched": {
  246. "value": "(.*)Joao(.*)"
  247. }
  248. }
  249. },
  250. {
  251. "regexp": {
  252. "phones.untouched": {
  253. "value": "(.*)Joao(.*)"
  254. }
  255. }
  256. }
  257. ]
  258. }
  259. }
  260. }
  261.  
  262. # Find people by pretty much everything haha
  263. GET /people/person/_search
  264. {
  265. "from":0,
  266. "size":10,
  267. "query":{
  268. "bool":{
  269. "should":[
  270. {
  271. "match":{
  272. "name":"6733267977"
  273. }
  274. },
  275. {
  276. "regexp":{
  277. "name.untouched":"(.*)6733267977(.*)"
  278. }
  279. }
  280. ,
  281. {
  282. "regexp":{
  283. "emails.untouched":"(.*)6733267977(.*)"
  284. }
  285. },
  286. {
  287. "regexp":{
  288. "phones.untouched":"(.*)6733267977(.*)"
  289. }
  290. }
  291. ]
  292. }
  293. },
  294. "highlight" : {
  295. "pre_tags" : ["<b>"],
  296. "post_tags" : ["</b>"],
  297. "fields" : {
  298. "name" : {
  299.  
  300. },
  301. "email" : {
  302.  
  303. },
  304. "phones" : {
  305.  
  306. }
  307. }
  308. }
  309. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement