1. ######### 查看原数据信息 ##########
    2. # 查看集群的健康状态
    3. GET _cat/health?v
    4. # 查看集群的 index
    5. GET _cat/indices?v
    6. GET _cat/plugins?v
    7. ##### ik 分词测试 ###
    8. GET _analyze
    9. {
    10. "analyzer": "ik_max_word"
    11. , "text": ["学习近平平安归来"]
    12. }
    13. ######### 数据的 PUT, POST, GET ###############
    14. DELETE student
    15. PUT student
    16. {
    17. "mappings": {
    18. "properties": {
    19. "name": {
    20. "type": "keyword"
    21. },
    22. "age": {
    23. "type": "integer"
    24. },
    25. "sex": {
    26. "type": "keyword"
    27. },
    28. "favo": {
    29. "type": "text",
    30. "analyzer": "ik_max_word"
    31. }
    32. }
    33. }
    34. }
    35. # PUT 操作
    36. PUT student/_doc/001
    37. {
    38. "name": "ylb",
    39. "age": "99",
    40. "sex": "男",
    41. "favo": "学习近平"
    42. }
    43. PUT student/_doc/002
    44. {
    45. "name": "y002",
    46. "age": "12",
    47. "sex": "女",
    48. "favo": "吃饭睡觉打豆豆..."
    49. }
    50. PUT student/_doc/003
    51. {
    52. "name": "y003",
    53. "age": "13",
    54. "sex": "女",
    55. "favo": "学习旅游行走"
    56. }
    57. PUT student/_doc/004
    58. {
    59. "name": "y004",
    60. "age": "13",
    61. "sex": "男",
    62. "favo": "学习旅行跑"
    63. }
    64. ### GET 查看 student 中的数据
    65. GET student/_search
    66. # POST 操作
    67. POST student/_doc
    68. {
    69. "name": "p004",
    70. "age": "14",
    71. "sex": "女",
    72. "favo": "敲代码"
    73. }
    74. ######### 检索 ############
    75. # 全文档检索
    76. GET student/_search
    77. #
    78. GET student/_search
    79. {
    80. "query": {
    81. "bool": {
    82. "filter": {
    83. "term": {
    84. "favo": "学习旅行"
    85. }
    86. }
    87. }
    88. }
    89. }
    90. # match: where ... or ...
    91. GET student/_search
    92. {
    93. "query": {
    94. "match": {
    95. "favo": "学习旅行"
    96. }
    97. }
    98. }
    99. # match: where ... and ...
    100. GET student/_search
    101. {
    102. "query": {
    103. "match": {
    104. "favo": {
    105. "query": "学习旅行",
    106. "operator": "and"
    107. }
    108. }
    109. }
    110. }
    111. # 多条件匹配: filter ... must ...
    112. GET student/_search
    113. {
    114. "query": {
    115. "bool": {
    116. "filter": {
    117. "term": {
    118. "sex": "男"
    119. }
    120. },
    121. "must": [
    122. {
    123. "match": {
    124. "favo": "学习"
    125. }
    126. },
    127. {
    128. "match": {
    129. "age": "13"
    130. }
    131. }
    132. ]
    133. }
    134. }
    135. }
    136. # 模糊匹配: fuzzy ,主要用来匹配英文
    137. GET student/_search
    138. {
    139. "query": {
    140. "fuzzy": {
    141. "name": {
    142. "value": "y00"
    143. }
    144. }
    145. },
    146. "from": 0,
    147. "size": 2
    148. }
    149. # 聚合操作: aggs
    150. GET student/_search
    151. {
    152. "aggs": {
    153. "group_by_sex": {
    154. "terms": {
    155. "field": "sex",
    156. "size": 2
    157. }
    158. },
    159. "group_age":{
    160. "max": {
    161. "field": "age"
    162. }
    163. }
    164. }
    165. }
    166. # 分页显示操作: from
    167. ## 显示第0页的2条数据
    168. GET student/_search
    169. {
    170. "from": 0,
    171. "size": 2
    172. }
    173. ## 统计 "学习" 有多少人,最大年龄的是多少
    174. GET student/_search
    175. {
    176. "query": {
    177. "bool": {
    178. "filter": {
    179. "term": {
    180. "favo": "学习"
    181. }
    182. },
    183. "must": [
    184. {"match": {
    185. "sex": "男"
    186. }}
    187. ]
    188. }
    189. },
    190. "aggs": {
    191. "group_age": {
    192. "max": {
    193. "field": "age"
    194. }
    195. }
    196. },
    197. "from": 0,
    198. "size": 20
    199. }
    200. ### -----------------------------test -------------------------------------- ###
    201. DELETE test01
    202. PUT test01
    203. {
    204. "mappings": {
    205. "properties": {
    206. "name": {
    207. "type": "keyword"
    208. },
    209. "age": {
    210. "type": "integer"
    211. }
    212. }
    213. }
    214. }
    215. GET test01/_search
    216. PUT test01/_doc/001
    217. {
    218. "name": "N001",
    219. "age": "12"
    220. }
    221. GET test01/_search