Advertisement
Guest User

Untitled

a guest
Aug 27th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. # Delete the `my_index` index
  2. DELETE /people
  3.  
  4. # Map the `postcode` to be not_analyzed
  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. "email":{
  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. }
  65. }
  66. }
  67. }
  68.  
  69. # Index some example docs
  70. PUT /people/person/_bulk
  71. {"index":{"_id":1}}
  72. {"name":"Luiz Freneda", "email":"lfreneda@gmail.com", "tags":["developer", "elasticsearcher", "cto"]}
  73. {"index":{"_id":2}}
  74. {"name":"Eduardo Santos", "email":"eduardoluizsantos@gmail.com", "tags":["developer", "ceo", "show-man"]}
  75. {"index":{"_id":3}}
  76. {"name":"Joao Sem acento", "email":"joaosemacento@hotmail.com", "tags":["user"]}
  77. {"index":{"_id":4}}
  78. {"name":"João Com acento", "email":"joaocomacento@yahoo.com", "tags":["user"]}
  79.  
  80. # Find people by emails
  81. GET /people/person/_search
  82. {
  83. "from":0,
  84. "size":10,
  85. "query":{
  86. "simple_query_string": {
  87. "query": "name:(lfreneda) OR email:(lfreneda)",
  88. "flags" : "OR|AND|PREFIX"
  89. }
  90. },
  91. "highlight" : {
  92. "pre_tags" : ["<b>"],
  93. "post_tags" : ["</b>"],
  94. "fields" : {
  95. "name" : {
  96. "fragment_size": 20,
  97. "number_of_fragments": 3
  98. },
  99. "email":{
  100. "fragment_size": 20,
  101. "number_of_fragments": 3
  102. }
  103. }
  104. }
  105. }
  106.  
  107. # Find people by name and tags
  108. GET /people/person/_search
  109. {
  110. "from":0,
  111. "size":10,
  112. "query":{
  113. "bool":{
  114. "should":[
  115. {
  116. "match":{
  117. "name":"Joao"
  118. }
  119. },
  120. {
  121. "regexp":{
  122. "name.untouched":"(.*)Jo[a|ã]o(.*)"
  123. }
  124. }
  125. ],
  126. "must":[
  127. {
  128. "match":{
  129. "tags":"user"
  130. }
  131. }
  132. ],
  133. "minimum_should_match":"100%"
  134. }
  135. },
  136. "highlight" : {
  137. "pre_tags" : ["<b>"],
  138. "post_tags" : ["</b>"],
  139. "fields" : {
  140. "name" : {
  141.  
  142. }
  143. }
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement