一、ES的安装与启动
1、ES安装(Windows环境)
- 下载地址:https://www.elastic.co/cn/downloads/past-releases#elasticsearch
- 版本:6.3.2
- 运行环境:jdk1.8以上
- 双击.bat启动
2、查看效果
浏览器输入:http://localhost:9200,返回如下json。
{ "name" : "RDFnj43", "cluster_name" : "elasticsearch", "cluster_uuid" : "X-h3NABsTPOitRIeqIJj4Q", "version" : { "number" : "6.3.2", "build_flavor" : "default", "build_type" : "zip", "build_hash" : "053779d", "build_date" : "2018-07-20T05:20:23.451332Z", "build_snapshot" : false, "lucene_version" : "7.3.1", "minimum_wire_compatibility_version" : "5.6.0", "minimum_index_compatibility_version" : "5.0.0" }, "tagline" : "You Know, for Search" }
证明启动成功
二、kibana安装及启动
1、kibana安装(Windows环境)
- 下载地址:https://www.elastic.co/cn/downloads/past-releases#kibana
- 版本:6.3.2
- 运行环境:jdk1.8以上
- 双击.bat启动
2、查看效果
浏览器输入:http://localhost:5601,如下所示,证明启动成功
三、交互操作
1、ES与mysql的对应关系理解
2、使用postman与ES交互操作案例
{ "id": "7b72aa64-67f2-5276-9f9f-f50d5c4ef1ef", "name": "ES与postman交互", "description": "", "order": [ "ed0c094d-ad2f-c724-0537-030a693b36dc", "0ea20269-f2b9-2f40-f8e6-06d09609bf16", "77d672e4-9ad5-6184-530f-b12c29501f76", "8935a2f2-5e8b-ec82-4633-f5bbfcbdc1b1", "e4bdcf5a-c4df-39c3-75a4-82285cc98af0", "72a69b67-c537-c442-d684-dae1f0cd38a6", "c04a38a6-d13a-d63c-4d2f-149c4072cdcb", "f8fe5a0d-05e4-fa30-76b5-2cae83c29928" ], "folders": [], "folders_order": [], "timestamp": 1575722536609, "owner": 0, "public": false, "requests": [ { "id": "0ea20269-f2b9-2f40-f8e6-06d09609bf16", "headers": "", "headerData": [], "url": "http://localhost:9200/test", "queryParams": [], "preRequestScript": null, "pathVariables": {}, "pathVariableData": [], "method": "PUT", "data": null, "dataMode": "params", "version": 2, "tests": null, "currentHelper": "normal", "helperAttributes": {}, "time": 1575722819075, "name": "创建索引-test", "description": "http://localhost:9200/_all", "collectionId": "7b72aa64-67f2-5276-9f9f-f50d5c4ef1ef", "responses": [] }, { "id": "72a69b67-c537-c442-d684-dae1f0cd38a6", "headers": "Content-Type: application/json\n", "headerData": [ { "key": "Content-Type", "value": "application/json", "description": "", "enabled": true } ], "url": "http://localhost:9200/person/_doc/2", "queryParams": [], "pathVariables": {}, "pathVariableData": [], "preRequestScript": null, "method": "PUT", "collectionId": "7b72aa64-67f2-5276-9f9f-f50d5c4ef1ef", "data": [], "dataMode": "raw", "name": "新增数据-person2", "description": "", "descriptionFormat": "html", "time": 1575724045084, "version": 2, "responses": [], "tests": null, "currentHelper": "normal", "helperAttributes": {}, "rawModeData": "{\r\n\t\"userName\": \"ESRC\",\r\n\t\"age\": 22,\r\n\t\"interests\": [\"PLAY GAME\", \"FOOTBALL\"]\r\n}" }, { "id": "77d672e4-9ad5-6184-530f-b12c29501f76", "headers": "", "headerData": [], "url": "http://localhost:9200/test", "queryParams": [], "pathVariables": {}, "pathVariableData": [], "preRequestScript": null, "method": "DELETE", "collectionId": "7b72aa64-67f2-5276-9f9f-f50d5c4ef1ef", "data": null, "dataMode": "params", "name": "删除索引-test", "description": "", "descriptionFormat": "html", "time": 1575722861291, "version": 2, "responses": [], "tests": null, "currentHelper": "normal", "helperAttributes": {} }, { "id": "8935a2f2-5e8b-ec82-4633-f5bbfcbdc1b1", "headers": "", "headerData": [], "url": "http://localhost:9200/person", "queryParams": [], "pathVariables": {}, "pathVariableData": [], "preRequestScript": null, "method": "PUT", "collectionId": "7b72aa64-67f2-5276-9f9f-f50d5c4ef1ef", "data": null, "dataMode": "params", "name": "创建索引persion", "description": "", "descriptionFormat": "html", "time": 1575722978016, "version": 2, "responses": [], "tests": null, "currentHelper": "normal", "helperAttributes": {} }, { "id": "c04a38a6-d13a-d63c-4d2f-149c4072cdcb", "headers": "Content-Type: application/json\n", "headerData": [ { "key": "Content-Type", "value": "application/json", "description": "", "enabled": true } ], "url": "http://localhost:9200/person/_doc/1", "queryParams": [], "pathVariables": {}, "pathVariableData": [], "preRequestScript": null, "method": "GET", "collectionId": "7b72aa64-67f2-5276-9f9f-f50d5c4ef1ef", "data": [], "dataMode": "raw", "name": "按照id查询", "description": "", "descriptionFormat": "html", "time": 1575724086023, "version": 2, "responses": [], "tests": null, "currentHelper": "normal", "helperAttributes": {}, "rawModeData": "{\r\n\t\"userName\": \"tom\",\r\n\t\"age\": 19,\r\n\t\"interests\": [\"music\", \"sports\"]\r\n}" }, { "id": "e4bdcf5a-c4df-39c3-75a4-82285cc98af0", "headers": "Content-Type: application/json\n", "headerData": [ { "key": "Content-Type", "value": "application/json", "description": "", "enabled": true } ], "url": "http://localhost:9200/person/_doc/1", "queryParams": [], "preRequestScript": null, "pathVariables": {}, "pathVariableData": [], "method": "PUT", "data": [], "dataMode": "raw", "tests": null, "currentHelper": "normal", "helperAttributes": {}, "time": 1575724010195, "name": "新增数据-person", "description": "", "collectionId": "7b72aa64-67f2-5276-9f9f-f50d5c4ef1ef", "responses": [], "rawModeData": "{\r\n\t\"userName\": \"tom\",\r\n\t\"age\": 19,\r\n\t\"interests\": [\"music\", \"sports\"]\r\n}" }, { "id": "ed0c094d-ad2f-c724-0537-030a693b36dc", "headers": "", "headerData": [], "url": "http://localhost:9200/_all", "queryParams": [], "preRequestScript": null, "pathVariables": {}, "pathVariableData": [], "method": "GET", "data": null, "dataMode": "params", "version": 2, "tests": null, "currentHelper": "normal", "helperAttributes": {}, "time": 1575722733199, "name": "查看所有索引", "description": "http://localhost:9200/_all", "collectionId": "7b72aa64-67f2-5276-9f9f-f50d5c4ef1ef", "responses": [] }, { "id": "f8fe5a0d-05e4-fa30-76b5-2cae83c29928", "headers": "Content-Type: application/json\n", "headerData": [ { "key": "Content-Type", "value": "application/json", "description": "", "enabled": true } ], "url": "http://localhost:9200/person/_doc/_search?q=userName:tom", "queryParams": [ { "key": "q", "value": "userName:tom", "equals": true, "description": "", "enabled": true } ], "pathVariables": {}, "pathVariableData": [], "preRequestScript": null, "method": "GET", "collectionId": "7b72aa64-67f2-5276-9f9f-f50d5c4ef1ef", "data": [], "dataMode": "raw", "name": "按照用户名查询", "description": "", "descriptionFormat": "html", "time": 1575724275505, "version": 2, "responses": [], "tests": null, "currentHelper": "normal", "helperAttributes": {}, "rawModeData": "{\r\n\t\"userName\": \"tom\",\r\n\t\"age\": 19,\r\n\t\"interests\": [\"music\", \"sports\"]\r\n}" } ] }
- GET为查询操作
- PUT为创建索引
- DELETE为删除索引
3、使用kibana与ES交互操作
找到dev tools,进行交互操作
//查询所有的索引 GET _all1//按照id查询GET person/_doc/2
与es交互式操作格式:
POST /person/_search { "query": { "bool": { "must": [ { "match": { "interests": "FOOTBALL" } }, { "match": { "userName": "ESRC22" } } ] } } }
- must为且的关系
- must处为should的时候为或的关系
原文地址:https://www.cnblogs.com/longronglang/p/12006939.html
时间: 2024-10-04 04:34:59