create_index.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. #!/usr/bin/env bash
  2. curl -XDELETE 'http://192.168.0.109:9200/index/'
  3. curl -XPUT 'http://192.168.0.109:9200/index/' -d '{
  4. "settings": {
  5. "index": {
  6. "number_of_shards": 1,
  7. "number_of_replicas": 0
  8. }
  9. },
  10. "mappings": {
  11. "library": {
  12. "properties": {
  13. "name": {
  14. "type": "string",
  15. "index": "not_analyzed"
  16. },
  17. "manager": {
  18. "type": "object",
  19. "properties": {
  20. "managerName": {
  21. "type": "string",
  22. "index": "not_analyzed"
  23. },
  24. "floors": {
  25. "type": "nested",
  26. "properties": {
  27. "floorNum": {
  28. "type": "integer"
  29. },
  30. "area": {
  31. "type": "string",
  32. "index": "not_analyzed"
  33. }
  34. }
  35. }
  36. }
  37. },
  38. "bookCategories": {
  39. "type": "nested",
  40. "properties": {
  41. "categoryName": {
  42. "type": "string",
  43. "index": "not_analyzed"
  44. },
  45. "categoryCode": {
  46. "type": "string",
  47. "index": "not_analyzed"
  48. },
  49. "books": {
  50. "type": "nested",
  51. "properties": {
  52. "bookStock": {
  53. "type": "integer"
  54. },
  55. "bookAuthor": {
  56. "type": "string",
  57. "index": "not_analyzed"
  58. },
  59. "bookName": {
  60. "type": "string",
  61. "index": "not_analyzed"
  62. },
  63. "bookPublisher" : {
  64. "type" : "object",
  65. "properties" : {
  66. "publisherName" : {
  67. "type" : "string",
  68. "index": "not_analyzed"
  69. },
  70. "publisherCode" : {
  71. "type" : "string",
  72. "index": "not_analyzed"
  73. },
  74. "bookProvider" : {
  75. "type" : "nested",
  76. "properties" : {
  77. "providerName" : {
  78. "type" : "string",
  79. "index": "not_analyzed"
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }'
  93. curl -XPUT 'http://192.168.0.109:9200/index/library/1' -d '{
  94. "name": "HBUT",
  95. "manager": {
  96. "managerName": "CN",
  97. "floors": [{
  98. "floorNum": 1,
  99. "area": ["A","B"]
  100. },
  101. {
  102. "floorNum": 2,
  103. "area": ["A","B","C"]
  104. }]
  105. },
  106. "bookCategories": [{
  107. "categoryName": "IT",
  108. "categoryCode": "C001",
  109. "books": [{
  110. "bookName": "Java Core",
  111. "bookStock": 22,
  112. "bookAuthor": "jason"
  113. },
  114. {
  115. "bookName": "Multi Thread",
  116. "bookStock": 12,
  117. "bookAuthor": "jason"
  118. }]
  119. },
  120. {
  121. "categoryName": "ART",
  122. "categoryCode": "C002",
  123. "books": [{
  124. "bookName": "Chinese 5000",
  125. "bookStock": 13,
  126. "bookAuthor": "bibic"
  127. },
  128. {
  129. "bookName": "qgjq",
  130. "bookStock": 18,
  131. "bookAuthor": "lcy"
  132. }]
  133. }]
  134. }'
  135. curl -XPUT 'http://192.168.0.109:9200/index/library/2' -d '{
  136. "name" : "HZKJDX",
  137. "manager" : {
  138. "managerName": "lcy",
  139. "floors": [{
  140. "floorNum" : 1,
  141. "area" : ["M", "X"]
  142. },
  143. {
  144. "floorNum" : 2,
  145. "area" : ["A"]
  146. },
  147. {
  148. "floorNum" : 4,
  149. "area" : ["N"]
  150. }]
  151. },
  152. "bookCategories" : [{
  153. "categoryName" : "NEWS",
  154. "categoryCode" : "C001",
  155. "books" : [{
  156. "bookName" : "cqcb",
  157. "bookStock" : 22,
  158. "bookAuthor" : "cq"
  159. },
  160. {
  161. "bookName" : "yyxw",
  162. "bookStock" : 12,
  163. "bookAuthor" : "cq"
  164. }]
  165. },
  166. {
  167. "categoryName" : "ART",
  168. "categoryCode" : "C002",
  169. "books" : [{
  170. "bookName" : "Cinese 5000",
  171. "bookStock" : 13,
  172. "bookAuthor" : "bibicx",
  173. "bookPublisher" : {
  174. "publisherName" : "CQ_PUB",
  175. "publisherCode" : "PUB_03",
  176. "bookProvider" : [{
  177. "providerName" : "PVD_01"
  178. }]
  179. }
  180. },
  181. {
  182. "bookName" : "qgjq",
  183. "bookStock" : 18,
  184. "bookAuthor" : "lcy"
  185. }]
  186. }]
  187. }'
  188. curl -XPOST 'http://192.168.0.109:9200/index/_refresh'
  189. curl -XPOST 'http://192.168.0.109:9200/index/_search' -d '{
  190. "query": {
  191. "filtered": {
  192. "filter": {
  193. "nested": {
  194. "path": "bookCategories",
  195. "filter": {
  196. "bool": {
  197. "must": [
  198. {
  199. "term": {
  200. "bookCategories.categoryName": "ART"
  201. }
  202. }
  203. ]
  204. }
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }'
  211. curl -XPOST 'http://192.168.0.109:9200/index/_search' -d '{
  212. "query": {
  213. "filtered": {
  214. "filter": {
  215. "nested": {
  216. "path": "manager.floors",
  217. "filter": {
  218. "bool": {
  219. "must": [
  220. {
  221. "term": {
  222. "manager.floors.floorNum": 1
  223. }
  224. }
  225. ]
  226. }
  227. }
  228. }
  229. }
  230. }
  231. }
  232. }'
  233. curl -XPOST 'http://192.168.0.109:9200/index/_search' -d '{
  234. "query": {
  235. "filtered": {
  236. "filter": {
  237. "nested": {
  238. "filter": {
  239. "bool": {
  240. "must": [
  241. {
  242. "term": {
  243. "bookCategories.categoryName": "ART"
  244. }
  245. },
  246. {
  247. "nested": {
  248. "filter": {
  249. "bool": {
  250. "must": {
  251. "terms": {
  252. "bookCategories.books.bookAuthor": [
  253. "bibicx"
  254. ]
  255. }
  256. }
  257. }
  258. },
  259. "path": "bookCategories.books"
  260. }
  261. }
  262. ]
  263. }
  264. },
  265. "path": "bookCategories"
  266. }
  267. }
  268. }
  269. }
  270. }'