├── .gitignore ├── LICENSE ├── README.md ├── doc ├── 1-1_课程介绍.md ├── 2-1_ES版本历史和选择.md ├── 2-2_单实例安装.md ├── 2-3_插件安装.md ├── 2-4_分布式安装.md ├── 3-1_基础概念.md ├── 4-1_索引创建.md ├── 4-2_插入.md ├── 4-3_修改.md ├── 4-4_删除.md ├── 4-5_查询.md ├── 5-1_query.md ├── 5-2_filter.md ├── 5-3_复合查询.md ├── 6-1_SpringBoot集成ElasticSearch.md ├── 6-2_查询接口开发.md ├── 6-3_增加接口开发.md ├── 6-4_删除接口开发.md ├── 6-5_更新接口开发.md ├── 6-6_复合查询接口开发.md ├── 7-1_课程总结.md ├── data │ └── books.data └── img │ ├── elasticsearch-head.png │ ├── elasticsearch-head_cluster.png │ ├── elasticsearch-head_index.png │ ├── elasticsearch-postman.png │ ├── es_data_people.png │ ├── es_data_people_update.png │ ├── 瓦力老师.jpg │ ├── 获取Elastic下载地址.png │ └── 集群和节点.png ├── pom.xml └── src └── main ├── java └── com │ └── imooc │ └── elasticsearch │ ├── Application.java │ └── MyConfig.java └── resources └── log4j2.properties /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/java,linux,macos,eclipse,windows,intellij 3 | 4 | ### Eclipse ### 5 | 6 | .metadata 7 | bin/ 8 | tmp/ 9 | *.tmp 10 | *.bak 11 | *.swp 12 | *~.nib 13 | local.properties 14 | .settings/ 15 | .loadpath 16 | .recommenders 17 | 18 | # External tool builders 19 | .externalToolBuilders/ 20 | 21 | # Locally stored "Eclipse launch configurations" 22 | *.launch 23 | 24 | # PyDev specific (Python IDE for Eclipse) 25 | *.pydevproject 26 | 27 | # CDT-specific (C/C++ Development Tooling) 28 | .cproject 29 | 30 | # Java annotation processor (APT) 31 | .factorypath 32 | 33 | # PDT-specific (PHP Development Tools) 34 | .buildpath 35 | 36 | # sbteclipse plugin 37 | .target 38 | 39 | # Tern plugin 40 | .tern-project 41 | 42 | # TeXlipse plugin 43 | .texlipse 44 | 45 | # STS (Spring Tool Suite) 46 | .springBeans 47 | 48 | # Code Recommenders 49 | .recommenders/ 50 | 51 | # Scala IDE specific (Scala & Java development for Eclipse) 52 | .cache-main 53 | .scala_dependencies 54 | .worksheet 55 | 56 | ### Eclipse Patch ### 57 | # Eclipse Core 58 | .project 59 | 60 | # JDT-specific (Eclipse Java Development Tools) 61 | .classpath 62 | 63 | ### Intellij ### 64 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm 65 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 66 | 67 | # User-specific stuff: 68 | .idea/**/workspace.xml 69 | .idea/**/tasks.xml 70 | .idea/dictionaries 71 | 72 | # Sensitive or high-churn files: 73 | .idea/**/dataSources/ 74 | .idea/**/dataSources.ids 75 | .idea/**/dataSources.xml 76 | .idea/**/dataSources.local.xml 77 | .idea/**/sqlDataSources.xml 78 | .idea/**/dynamic.xml 79 | .idea/**/uiDesigner.xml 80 | 81 | # Gradle: 82 | .idea/**/gradle.xml 83 | .idea/**/libraries 84 | 85 | # CMake 86 | cmake-build-debug/ 87 | 88 | # Mongo Explorer plugin: 89 | .idea/**/mongoSettings.xml 90 | 91 | ## File-based project format: 92 | *.iws 93 | 94 | ## Plugin-specific files: 95 | 96 | # IntelliJ 97 | /out/ 98 | 99 | # mpeltonen/sbt-idea plugin 100 | .idea_modules/ 101 | 102 | # JIRA plugin 103 | atlassian-ide-plugin.xml 104 | 105 | # Cursive Clojure plugin 106 | .idea/replstate.xml 107 | 108 | # Ruby plugin and RubyMine 109 | /.rakeTasks 110 | 111 | # Crashlytics plugin (for Android Studio and IntelliJ) 112 | com_crashlytics_export_strings.xml 113 | crashlytics.properties 114 | crashlytics-build.properties 115 | fabric.properties 116 | 117 | ### Intellij Patch ### 118 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 119 | 120 | # *.iml 121 | # modules.xml 122 | # .idea/misc.xml 123 | # *.ipr 124 | 125 | # Sonarlint plugin 126 | .idea/sonarlint 127 | 128 | ### Java ### 129 | # Compiled class file 130 | *.class 131 | 132 | # Log file 133 | *.log 134 | 135 | # BlueJ files 136 | *.ctxt 137 | 138 | # Mobile Tools for Java (J2ME) 139 | .mtj.tmp/ 140 | 141 | # Package Files # 142 | *.jar 143 | *.war 144 | *.ear 145 | *.zip 146 | *.tar.gz 147 | *.rar 148 | 149 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 150 | hs_err_pid* 151 | 152 | ### Linux ### 153 | *~ 154 | 155 | # temporary files which can be created if a process still has a handle open of a deleted file 156 | .fuse_hidden* 157 | 158 | # KDE directory preferences 159 | .directory 160 | 161 | # Linux trash folder which might appear on any partition or disk 162 | .Trash-* 163 | 164 | # .nfs files are created when an open file is removed but is still being accessed 165 | .nfs* 166 | 167 | ### macOS ### 168 | *.DS_Store 169 | .AppleDouble 170 | .LSOverride 171 | 172 | # Icon must end with two \r 173 | Icon 174 | 175 | # Thumbnails 176 | ._* 177 | 178 | # Files that might appear in the root of a volume 179 | .DocumentRevisions-V100 180 | .fseventsd 181 | .Spotlight-V100 182 | .TemporaryItems 183 | .Trashes 184 | .VolumeIcon.icns 185 | .com.apple.timemachine.donotpresent 186 | 187 | # Directories potentially created on remote AFP share 188 | .AppleDB 189 | .AppleDesktop 190 | Network Trash Folder 191 | Temporary Items 192 | .apdisk 193 | 194 | ### Windows ### 195 | # Windows thumbnail cache files 196 | Thumbs.db 197 | ehthumbs.db 198 | ehthumbs_vista.db 199 | 200 | # Folder config file 201 | Desktop.ini 202 | 203 | # Recycle Bin used on file shares 204 | $RECYCLE.BIN/ 205 | 206 | # Windows Installer files 207 | *.cab 208 | *.msi 209 | *.msm 210 | *.msp 211 | 212 | # Windows shortcuts 213 | *.lnk 214 | 215 | 216 | # End of https://www.gitignore.io/api/java,linux,macos,eclipse,windows,intellij 217 | \.idea/ 218 | 219 | *.iml 220 | 221 | .sync/* 222 | 223 | .me_configs.data 224 | 225 | .z_sync_configs.data 226 | 227 | sync_changes.log 228 | 229 | sync_hook.script 230 | 231 | **/.Archive 232 | 233 | target/ 234 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 慕课网-Java 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ElasticSearch 入门 2 | 3 | 视频来源:https://www.imooc.com/learn/889 4 | 5 | 视频作者:[瓦力老师](https://www.imooc.com/t/5646367 "https://www.imooc.com/t/5646367") 6 | 7 | ![](./doc/img/瓦力老师.jpg) 8 | 9 | # 章节目录和总结文档 10 | 11 | ## 第1章 课程介绍 12 | 13 | * [x] [1-1 课程介绍 (08:17)](./doc/1-1_课程介绍.md) 14 | 15 | ## 第2章 安装 16 | 17 | * [x] [2-1 ES版本历史和选择 (01:55)](./doc/2-1_ES版本历史和选择.md) 18 | * [x] [2-2 单实例安装 (02:40)](./doc/2-2_单实例安装.md) 19 | * [x] [2-3 插件安装 (04:56)](./doc/2-3_插件安装.md) 20 | * [x] [2-4 分布式安装 (06:47)](./doc/2-4_分布式安装.md) 21 | 22 | ## 第3章 基础概念 23 | 24 | * [x] [3-1 基础概念 (04:20)](./doc/3-1_基础概念.md) 25 | 26 | ## 第4章 基本用法 27 | 28 | * [x] [4-1 索引创建 (07:00)](./doc/4-1_索引创建.md) 29 | * [x] [4-2 插入 (03:07)](./doc/4-2_插入.md) 30 | * [x] [4-3 修改 (03:36)](./doc/4-3_修改.md) 31 | * [x] [4-4 删除 (02:26)](./doc/4-4_删除.md) 32 | * [x] [4-5 查询 (08:05)](./doc/4-5_查询.md) 33 | 34 | ## 第5章 高级查询 35 | 36 | * [x] [5-1 query (09:01)](./doc/5-1_query.md) 37 | * [x] [5-2 filter (01:48)](./doc/5-2_filter.md) 38 | * [x] [5-3 复合查询 (06:00)](./doc/5-3_复合查询.md) 39 | 40 | ## 第6章 Spring Boot集成ES 41 | 42 | * [x] [6-1 SpringBoot集成ElasticSearch (05:21)](./doc/6-1_SpringBoot集成ElasticSearch.md) 43 | * [x] [6-2 查询接口开发 (03:37)](./doc/6-2_查询接口开发.md) 44 | * [x] [6-3 增加接口开发 (06:32)](./doc/6-3_增加接口开发.md) 45 | * [x] [6-4 删除接口开发 (02:51)](./doc/6-4_删除接口开发.md) 46 | * [x] [6-5 更新接口开发 (06:32)](./doc/6-5_更新接口开发.md) 47 | * [x] [6-6 复合查询接口开发 (08:23)](./doc/6-6_复合查询接口开发.md) 48 | 49 | ## 第7章 课程总结 50 | 51 | * [x] [7-1 课程总结 (02:10)](./doc/7-1_课程总结.md) 52 | 53 | -------------------------------------------------------------------------------- /doc/1-1_课程介绍.md: -------------------------------------------------------------------------------- 1 | # 1-1 课程介绍 2 | 3 | # ElasticSearch 简介 4 | 5 | ## 什么是 ElasticSearch 6 | 7 | 1. 基于 [Apache Lucene](https://lucene.apache.org/ "https://lucene.apache.org/") 构建的开源搜索引擎 8 | 2. 采用 Java 编写,提交简单易用的 RESTFul API 9 | 3. 轻松的横向扩展,可支持PB级的结构化或非结构化数据处理 10 | 11 | # 应用场景 12 | 13 | ## 可用应用场景 14 | 15 | 1. 海量数据分析引擎 16 | 2. 站内搜索引擎 17 | 3. 数据仓库 18 | 19 | ## 一线公司实际应用场景 20 | 21 | * 英国卫报 - 实时分析公众对文章的回应 22 | * 维基百科、Github - 站内实时搜索 23 | * 百度 - 实时日志监控平台 24 | 25 | ## 还有谁在用呢 26 | 27 | * 阿里巴巴 28 | * Google 29 | * 京东 30 | 31 | # 前置知识 32 | 33 | * 熟悉用 Maven 构建项目 34 | 35 | 项目管理利器——maven: https://www.imooc.com/learn/443 36 | 37 | * 了解 Spring Boot 的基本使用 38 | 39 | 2小时学会Spring Boot: https://www.imooc.com/learn/767 40 | 41 | # 环境要求 42 | 43 | * IDE 工具 IntelliJ IDEA、Eclipse 等常用 IDE 即可 44 | * Java JDK1.8 45 | * 其他依赖 Maven、NodeJS(6.0以上) 46 | 47 | # 课程简介 48 | 49 | ## 课程安排 50 | 51 | * 安装 52 | * 基础概念 53 | * 基本用法 54 | * 高级查询 55 | * 实战演练 56 | * 课程总结 57 | -------------------------------------------------------------------------------- /doc/2-1_ES版本历史和选择.md: -------------------------------------------------------------------------------- 1 | # 2-1 ES版本历史和选择 2 | 3 | # 安装 4 | 5 | ## 版本问题 6 | 7 | * 版本历史 8 | 9 | 1.x -> 2.x -> 5.x 10 | 11 | * 版本选择 12 | 13 | -------------------------------------------------------------------------------- /doc/2-2_单实例安装.md: -------------------------------------------------------------------------------- 1 | # 2-2 单实例安装 2 | 3 | * 下载页面:https://www.elastic.co/downloads/elasticsearch 4 | 5 | * 鼠标右键,获取下载地址 6 | 7 | ![](./img/获取Elastic下载地址.png) 8 | 9 | * 下载命令:`wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.2.tar.gz` 10 | 11 | > 为何我下载速度这么慢... 😭 12 | > elasticsearch-6.2.2.tar.gz 24%[=============> ] 6.85M 23.8KB/s eta 14m 15s 13 | 14 | * 解压命令:`tar -vxf elasticsearch-6.2.2.tar.gz` 15 | 16 | * 启动命令:`sh ./bin/elasticsearch` 17 | 18 | * 验证启动 19 | 20 | 打开浏览器,访问:http://localhost:9200/ 21 | 22 | ``` 23 | { 24 | "name" : "mF4GZ8u", 25 | "cluster_name" : "elasticsearch", 26 | "cluster_uuid" : "fE_Ex2l5SrS11AbWZYHvBA", 27 | "version" : { 28 | "number" : "6.2.2", 29 | "build_hash" : "10b1edd", 30 | "build_date" : "2018-02-16T19:01:30.685723Z", 31 | "build_snapshot" : false, 32 | "lucene_version" : "7.2.1", 33 | "minimum_wire_compatibility_version" : "5.6.0", 34 | "minimum_index_compatibility_version" : "5.0.0" 35 | }, 36 | "tagline" : "You Know, for Search" 37 | } 38 | ``` 39 | 40 | ## 详细步骤 41 | 42 | ``` 43 | CorningSunMac:local corning$ mkdir elastic 44 | CorningSunMac:local corning$ cd elastic/ 45 | CorningSunMac:elastic corning$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.2.tar.gz 46 | --2018-02-24 17:57:54-- https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.2.tar.gz 47 | Resolving artifacts.elastic.co... 23.23.109.100, 184.72.242.47, 184.73.245.233, ... 48 | Connecting to artifacts.elastic.co|23.23.109.100|:443... connected. 49 | HTTP request sent, awaiting response... 200 OK 50 | Length: 29049540 (28M) [application/x-gzip] 51 | Saving to: ‘elasticsearch-6.2.2.tar.gz’ 52 | 53 | elasticsearch-6.2.2.tar.gz 100%[==========================================================>] 27.70M 32.4KB/s in 17m 57s 54 | 55 | 2018-02-24 18:15:56 (26.3 KB/s) - ‘elasticsearch-6.2.2.tar.gz’ saved [29049540/29049540] 56 | 57 | CorningSunMac:elastic corning$ ls 58 | elasticsearch-6.2.2.tar.gz 59 | CorningSunMac:elastic corning$ tar -vxf elasticsearch-6.2.2.tar.gz 60 | x elasticsearch-6.2.2/ 61 | x elasticsearch-6.2.2/lib/ 62 | x elasticsearch-6.2.2/lib/elasticsearch-6.2.2.jar 63 | x elasticsearch-6.2.2/lib/elasticsearch-core-6.2.2.jar 64 | x elasticsearch-6.2.2/lib/lucene-core-7.2.1.jar 65 | x elasticsearch-6.2.2/lib/lucene-analyzers-common-7.2.1.jar 66 | x elasticsearch-6.2.2/lib/lucene-backward-codecs-7.2.1.jar 67 | x elasticsearch-6.2.2/lib/lucene-grouping-7.2.1.jar 68 | x elasticsearch-6.2.2/lib/lucene-highlighter-7.2.1.jar 69 | x elasticsearch-6.2.2/lib/lucene-join-7.2.1.jar 70 | x elasticsearch-6.2.2/lib/lucene-memory-7.2.1.jar 71 | x elasticsearch-6.2.2/lib/lucene-misc-7.2.1.jar 72 | x elasticsearch-6.2.2/lib/lucene-queries-7.2.1.jar 73 | x elasticsearch-6.2.2/lib/lucene-queryparser-7.2.1.jar 74 | x elasticsearch-6.2.2/lib/lucene-sandbox-7.2.1.jar 75 | x elasticsearch-6.2.2/lib/lucene-spatial-7.2.1.jar 76 | x elasticsearch-6.2.2/lib/lucene-spatial-extras-7.2.1.jar 77 | x elasticsearch-6.2.2/lib/lucene-spatial3d-7.2.1.jar 78 | x elasticsearch-6.2.2/lib/lucene-suggest-7.2.1.jar 79 | x elasticsearch-6.2.2/lib/securesm-1.2.jar 80 | x elasticsearch-6.2.2/lib/hppc-0.7.1.jar 81 | x elasticsearch-6.2.2/lib/joda-time-2.9.9.jar 82 | x elasticsearch-6.2.2/lib/snakeyaml-1.17.jar 83 | x elasticsearch-6.2.2/lib/jackson-core-2.8.10.jar 84 | x elasticsearch-6.2.2/lib/jackson-dataformat-smile-2.8.10.jar 85 | x elasticsearch-6.2.2/lib/jackson-dataformat-yaml-2.8.10.jar 86 | x elasticsearch-6.2.2/lib/jackson-dataformat-cbor-2.8.10.jar 87 | x elasticsearch-6.2.2/lib/t-digest-3.0.jar 88 | x elasticsearch-6.2.2/lib/HdrHistogram-2.1.9.jar 89 | x elasticsearch-6.2.2/lib/spatial4j-0.6.jar 90 | x elasticsearch-6.2.2/lib/jts-1.13.jar 91 | x elasticsearch-6.2.2/lib/log4j-api-2.9.1.jar 92 | x elasticsearch-6.2.2/lib/log4j-core-2.9.1.jar 93 | x elasticsearch-6.2.2/lib/log4j-1.2-api-2.9.1.jar 94 | x elasticsearch-6.2.2/lib/jna-4.5.1.jar 95 | x elasticsearch-6.2.2/lib/elasticsearch-cli-6.2.2.jar 96 | x elasticsearch-6.2.2/lib/jopt-simple-5.0.2.jar 97 | x elasticsearch-6.2.2/lib/plugin-classloader-6.2.2.jar 98 | x elasticsearch-6.2.2/lib/elasticsearch-launchers-6.2.2.jar 99 | x elasticsearch-6.2.2/lib/plugin-cli-6.2.2.jar 100 | x elasticsearch-6.2.2/config/ 101 | x elasticsearch-6.2.2/config/elasticsearch.yml 102 | x elasticsearch-6.2.2/config/jvm.options 103 | x elasticsearch-6.2.2/config/log4j2.properties 104 | x elasticsearch-6.2.2/bin/ 105 | x elasticsearch-6.2.2/bin/elasticsearch-env 106 | x elasticsearch-6.2.2/bin/elasticsearch 107 | x elasticsearch-6.2.2/bin/elasticsearch-plugin 108 | x elasticsearch-6.2.2/bin/elasticsearch-translog 109 | x elasticsearch-6.2.2/bin/elasticsearch-keystore 110 | x elasticsearch-6.2.2/bin/elasticsearch-env.bat 111 | x elasticsearch-6.2.2/bin/elasticsearch-keystore.bat 112 | x elasticsearch-6.2.2/bin/elasticsearch-service.bat 113 | x elasticsearch-6.2.2/bin/elasticsearch.bat 114 | x elasticsearch-6.2.2/bin/elasticsearch-translog.bat 115 | x elasticsearch-6.2.2/bin/elasticsearch-plugin.bat 116 | x elasticsearch-6.2.2/README.textile 117 | x elasticsearch-6.2.2/LICENSE.txt 118 | x elasticsearch-6.2.2/NOTICE.txt 119 | x elasticsearch-6.2.2/bin/elasticsearch-service-mgr.exe 120 | x elasticsearch-6.2.2/bin/elasticsearch-service-x64.exe 121 | x elasticsearch-6.2.2/modules/ 122 | x elasticsearch-6.2.2/modules/reindex/ 123 | x elasticsearch-6.2.2/modules/reindex/reindex-6.2.2.jar 124 | x elasticsearch-6.2.2/modules/reindex/httpcore-4.4.5.jar 125 | x elasticsearch-6.2.2/modules/reindex/httpcore-nio-4.4.5.jar 126 | x elasticsearch-6.2.2/modules/reindex/plugin-security.policy 127 | x elasticsearch-6.2.2/modules/reindex/elasticsearch-rest-client-6.2.2.jar 128 | x elasticsearch-6.2.2/modules/reindex/commons-logging-1.1.3.jar 129 | x elasticsearch-6.2.2/modules/reindex/httpasyncclient-4.1.2.jar 130 | x elasticsearch-6.2.2/modules/reindex/plugin-descriptor.properties 131 | x elasticsearch-6.2.2/modules/reindex/httpclient-4.5.2.jar 132 | x elasticsearch-6.2.2/modules/reindex/commons-codec-1.10.jar 133 | x elasticsearch-6.2.2/modules/rank-eval/ 134 | x elasticsearch-6.2.2/modules/rank-eval/rank-eval-6.2.2.jar 135 | x elasticsearch-6.2.2/modules/rank-eval/plugin-descriptor.properties 136 | x elasticsearch-6.2.2/modules/lang-painless/ 137 | x elasticsearch-6.2.2/modules/lang-painless/antlr4-runtime-4.5.3.jar 138 | x elasticsearch-6.2.2/modules/lang-painless/plugin-security.policy 139 | x elasticsearch-6.2.2/modules/lang-painless/lang-painless-6.2.2.jar 140 | x elasticsearch-6.2.2/modules/lang-painless/plugin-descriptor.properties 141 | x elasticsearch-6.2.2/modules/lang-painless/elasticsearch-scripting-painless-spi-6.2.2.jar 142 | x elasticsearch-6.2.2/modules/lang-painless/asm-debug-all-5.1.jar 143 | x elasticsearch-6.2.2/modules/repository-url/ 144 | x elasticsearch-6.2.2/modules/repository-url/plugin-security.policy 145 | x elasticsearch-6.2.2/modules/repository-url/plugin-descriptor.properties 146 | x elasticsearch-6.2.2/modules/repository-url/repository-url-6.2.2.jar 147 | x elasticsearch-6.2.2/modules/percolator/ 148 | x elasticsearch-6.2.2/modules/percolator/plugin-descriptor.properties 149 | x elasticsearch-6.2.2/modules/percolator/percolator-6.2.2.jar 150 | x elasticsearch-6.2.2/modules/tribe/ 151 | x elasticsearch-6.2.2/modules/tribe/tribe-6.2.2.jar 152 | x elasticsearch-6.2.2/modules/tribe/plugin-descriptor.properties 153 | x elasticsearch-6.2.2/modules/aggs-matrix-stats/ 154 | x elasticsearch-6.2.2/modules/aggs-matrix-stats/aggs-matrix-stats-6.2.2.jar 155 | x elasticsearch-6.2.2/modules/aggs-matrix-stats/plugin-descriptor.properties 156 | x elasticsearch-6.2.2/modules/transport-netty4/ 157 | x elasticsearch-6.2.2/modules/transport-netty4/netty-codec-4.1.16.Final.jar 158 | x elasticsearch-6.2.2/modules/transport-netty4/netty-buffer-4.1.16.Final.jar 159 | x elasticsearch-6.2.2/modules/transport-netty4/netty-common-4.1.16.Final.jar 160 | x elasticsearch-6.2.2/modules/transport-netty4/netty-codec-http-4.1.16.Final.jar 161 | x elasticsearch-6.2.2/modules/transport-netty4/transport-netty4-6.2.2.jar 162 | x elasticsearch-6.2.2/modules/transport-netty4/plugin-security.policy 163 | x elasticsearch-6.2.2/modules/transport-netty4/plugin-descriptor.properties 164 | x elasticsearch-6.2.2/modules/transport-netty4/netty-resolver-4.1.16.Final.jar 165 | x elasticsearch-6.2.2/modules/transport-netty4/netty-transport-4.1.16.Final.jar 166 | x elasticsearch-6.2.2/modules/transport-netty4/netty-handler-4.1.16.Final.jar 167 | x elasticsearch-6.2.2/modules/ingest-common/ 168 | x elasticsearch-6.2.2/modules/ingest-common/joni-2.1.6.jar 169 | x elasticsearch-6.2.2/modules/ingest-common/ingest-common-6.2.2.jar 170 | x elasticsearch-6.2.2/modules/ingest-common/plugin-descriptor.properties 171 | x elasticsearch-6.2.2/modules/ingest-common/jcodings-1.0.12.jar 172 | x elasticsearch-6.2.2/modules/analysis-common/ 173 | x elasticsearch-6.2.2/modules/analysis-common/plugin-descriptor.properties 174 | x elasticsearch-6.2.2/modules/analysis-common/analysis-common-6.2.2.jar 175 | x elasticsearch-6.2.2/modules/parent-join/ 176 | x elasticsearch-6.2.2/modules/parent-join/plugin-descriptor.properties 177 | x elasticsearch-6.2.2/modules/parent-join/parent-join-6.2.2.jar 178 | x elasticsearch-6.2.2/modules/lang-mustache/ 179 | x elasticsearch-6.2.2/modules/lang-mustache/plugin-security.policy 180 | x elasticsearch-6.2.2/modules/lang-mustache/lang-mustache-6.2.2.jar 181 | x elasticsearch-6.2.2/modules/lang-mustache/plugin-descriptor.properties 182 | x elasticsearch-6.2.2/modules/lang-mustache/compiler-0.9.3.jar 183 | x elasticsearch-6.2.2/modules/mapper-extras/ 184 | x elasticsearch-6.2.2/modules/mapper-extras/plugin-descriptor.properties 185 | x elasticsearch-6.2.2/modules/mapper-extras/mapper-extras-6.2.2.jar 186 | x elasticsearch-6.2.2/modules/lang-expression/ 187 | x elasticsearch-6.2.2/modules/lang-expression/asm-5.0.4.jar 188 | x elasticsearch-6.2.2/modules/lang-expression/lucene-expressions-7.2.1.jar 189 | x elasticsearch-6.2.2/modules/lang-expression/plugin-security.policy 190 | x elasticsearch-6.2.2/modules/lang-expression/asm-commons-5.0.4.jar 191 | x elasticsearch-6.2.2/modules/lang-expression/asm-tree-5.0.4.jar 192 | x elasticsearch-6.2.2/modules/lang-expression/antlr4-runtime-4.5.1-1.jar 193 | x elasticsearch-6.2.2/modules/lang-expression/plugin-descriptor.properties 194 | x elasticsearch-6.2.2/modules/lang-expression/lang-expression-6.2.2.jar 195 | x elasticsearch-6.2.2/plugins/ 196 | x elasticsearch-6.2.2/logs/ 197 | CorningSunMac:elastic corning$ ls 198 | elasticsearch-6.2.2 elasticsearch-6.2.2.tar.gz 199 | CorningSunMac:elastic corning$ cd elasticsearch-6.2.2 200 | CorningSunMac:elasticsearch-6.2.2 corning$ ls 201 | LICENSE.txt README.textile config logs plugins 202 | NOTICE.txt bin lib modules 203 | CorningSunMac:elasticsearch-6.2.2 corning$ java -version 204 | java version "9" 205 | Java(TM) SE Runtime Environment (build 9+181) 206 | Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode) 207 | CorningSunMac:elasticsearch-6.2.2 corning$ ls ./bin/ 208 | elasticsearch elasticsearch-keystore.bat elasticsearch-service-x64.exe elasticsearch.bat 209 | elasticsearch-env elasticsearch-plugin elasticsearch-service.bat 210 | elasticsearch-env.bat elasticsearch-plugin.bat elasticsearch-translog 211 | elasticsearch-keystore elasticsearch-service-mgr.exe elasticsearch-translog.bat 212 | CorningSunMac:elasticsearch-6.2.2 corning$ sh ./bin/elasticsearch 213 | Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. 214 | [2018-02-26T09:20:35,768][INFO ][o.e.n.Node ] [] initializing ... 215 | [2018-02-26T09:20:35,860][INFO ][o.e.e.NodeEnvironment ] [mF4GZ8u] using [1] data paths, mounts [[/ (/dev/disk1s1)]], net usable_space [108.8gb], net total_space [465.7gb], types [apfs] 216 | [2018-02-26T09:20:35,860][INFO ][o.e.e.NodeEnvironment ] [mF4GZ8u] heap size [989.8mb], compressed ordinary object pointers [true] 217 | [2018-02-26T09:20:35,863][INFO ][o.e.n.Node ] node name [mF4GZ8u] derived from node ID [mF4GZ8u0T8eKC8iHNzTt_w]; set [node.name] to override 218 | [2018-02-26T09:20:35,863][INFO ][o.e.n.Node ] version[6.2.2], pid[10992], build[10b1edd/2018-02-16T19:01:30.685723Z], OS[Mac OS X/10.13.3/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/9/9+181] 219 | [2018-02-26T09:20:35,863][INFO ][o.e.n.Node ] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/var/folders/mg/pxtj807539j2bbfwcmfprsw80000gn/T/elasticsearch.iSw4klBZ, -XX:+HeapDumpOnOutOfMemoryError, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Djava.locale.providers=COMPAT, -Des.path.home=/Users/corning/local/elastic/elasticsearch-6.2.2, -Des.path.conf=/Users/corning/local/elastic/elasticsearch-6.2.2/config] 220 | [2018-02-26T09:20:36,336][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [aggs-matrix-stats] 221 | [2018-02-26T09:20:36,336][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [analysis-common] 222 | [2018-02-26T09:20:36,336][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [ingest-common] 223 | [2018-02-26T09:20:36,336][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [lang-expression] 224 | [2018-02-26T09:20:36,336][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [lang-mustache] 225 | [2018-02-26T09:20:36,337][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [lang-painless] 226 | [2018-02-26T09:20:36,337][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [mapper-extras] 227 | [2018-02-26T09:20:36,337][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [parent-join] 228 | [2018-02-26T09:20:36,337][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [percolator] 229 | [2018-02-26T09:20:36,337][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [rank-eval] 230 | [2018-02-26T09:20:36,338][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [reindex] 231 | [2018-02-26T09:20:36,338][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [repository-url] 232 | [2018-02-26T09:20:36,338][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [transport-netty4] 233 | [2018-02-26T09:20:36,338][INFO ][o.e.p.PluginsService ] [mF4GZ8u] loaded module [tribe] 234 | [2018-02-26T09:20:36,338][INFO ][o.e.p.PluginsService ] [mF4GZ8u] no plugins loaded 235 | [2018-02-26T09:20:38,239][INFO ][o.e.d.DiscoveryModule ] [mF4GZ8u] using discovery type [zen] 236 | [2018-02-26T09:20:38,658][INFO ][o.e.n.Node ] initialized 237 | [2018-02-26T09:20:38,658][INFO ][o.e.n.Node ] [mF4GZ8u] starting ... 238 | [2018-02-26T09:20:38,793][INFO ][o.e.t.TransportService ] [mF4GZ8u] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300} 239 | [2018-02-26T09:20:41,833][INFO ][o.e.c.s.MasterService ] [mF4GZ8u] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {mF4GZ8u}{mF4GZ8u0T8eKC8iHNzTt_w}{p83JSVB0SzuGEule4Uo74Q}{127.0.0.1}{127.0.0.1:9300} 240 | [2018-02-26T09:20:41,838][INFO ][o.e.c.s.ClusterApplierService] [mF4GZ8u] new_master {mF4GZ8u}{mF4GZ8u0T8eKC8iHNzTt_w}{p83JSVB0SzuGEule4Uo74Q}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {mF4GZ8u}{mF4GZ8u0T8eKC8iHNzTt_w}{p83JSVB0SzuGEule4Uo74Q}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]]) 241 | [2018-02-26T09:20:41,853][INFO ][o.e.h.n.Netty4HttpServerTransport] [mF4GZ8u] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200} 242 | [2018-02-26T09:20:41,853][INFO ][o.e.n.Node ] [mF4GZ8u] started 243 | [2018-02-26T09:20:41,879][INFO ][o.e.g.GatewayService ] [mF4GZ8u] recovered [0] indices into cluster_state 244 | 245 | ``` 246 | -------------------------------------------------------------------------------- /doc/2-3_插件安装.md: -------------------------------------------------------------------------------- 1 | # 2-3 插件安装 2 | 3 | ## elasticsearch-head 4 | 5 | https://github.com/mobz/elasticsearch-head 6 | 7 | ### 为什么要使用Head插件? 8 | 9 | * es返回的服务信息是json格式的,阅读等对于用户而言不是很友好 10 | * Head则提供了友好的Web页面,方便阅读,可以集成了基本的查询 11 | 12 | ### 安装 elasticsearch-head 13 | 14 | 1. 下载或 git clone elasticsearch-head 15 | 16 | 2. 确认 node >= 6.0 17 | 18 | 3. npm install 19 | 20 | 4. npm run start 21 | 22 | 5. 检查运行结果 23 | 24 | 浏览器访问:http://localhost:9100 25 | 26 | ### 配置 elasticsearch 27 | 28 | 1. 修改 elasticsearch/config/elasticsearch.yml 29 | 30 | 添加 31 | ``` 32 | http.cors.enabled: true 33 | http.cors.allow-origin: "*" 34 | ``` 35 | 36 | 2. 启动 elasticsearch 37 | 38 | 3. 启动 elasticsearch-head 39 | 40 | ![](./img/elasticsearch-head.png) 41 | 42 | ### 集群状态 43 | 44 | * green 绿色: 集群运行良好 45 | * yellow 黄色: 集群健康不是很好,但是可以正常使用 46 | * red 红色: 集群运行不好, 已经开始丢失数据了 47 | 48 | ### 详细步骤 49 | 50 | ``` 51 | CorningSunMac:elastic corning$ ls 52 | elasticsearch-6.2.2 elasticsearch-6.2.2.tar.gz 53 | CorningSunMac:elastic corning$ git clone git@github.com:mobz/elasticsearch-head.git 54 | Cloning into 'elasticsearch-head'... 55 | remote: Counting objects: 4224, done. 56 | remote: Total 4224 (delta 0), reused 0 (delta 0), pack-reused 4224 57 | Receiving objects: 100% (4224/4224), 2.16 MiB | 6.00 KiB/s, done. 58 | Resolving deltas: 100% (2329/2329), done. 59 | CorningSunMac:elastic corning$ ls 60 | elasticsearch-6.2.2 elasticsearch-6.2.2.tar.gz elasticsearch-head 61 | CorningSunMac:elastic corning$ node -v 62 | v6.9.2 63 | CorningSunMac:elastic corning$ cd elasticsearch-head/ 64 | CorningSunMac:elasticsearch-head corning$ ls 65 | Dockerfile README.textile index.html src 66 | Dockerfile-alpine _site package.json test 67 | Gruntfile.js elasticsearch-head.sublime-project plugin-descriptor.properties 68 | LICENCE grunt_fileSets.js proxy 69 | CorningSunMac:elasticsearch-head corning$ npm install 70 | npm WARN deprecated coffee-script@1.10.0: CoffeeScript on NPM has moved to "coffeescript" (no hyphen) 71 | npm WARN deprecated http2@3.3.7: Use the built-in module in node 9.0.0 or newer, instead 72 | npm WARN prefer global coffee-script@1.10.0 should be installed with -g 73 | 74 | > fsevents@1.1.3 install /Users/corning/local/elastic/elasticsearch-head/node_modules/fsevents 75 | > node install 76 | 77 | [fsevents] Success: "/Users/corning/local/elastic/elasticsearch-head/node_modules/fsevents/lib/binding/Release/node-v48-darwin-x64/fse.node" already installed 78 | Pass --update-binary to reinstall or --build-from-source to recompile 79 | 80 | > phantomjs-prebuilt@2.1.16 install /Users/corning/local/elastic/elasticsearch-head/node_modules/phantomjs-prebuilt 81 | > node install.js 82 | 83 | PhantomJS not found on PATH 84 | Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-macosx.zip 85 | Saving to /var/folders/mg/pxtj807539j2bbfwcmfprsw80000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip 86 | Receiving... 87 | [======================================--] 96% 88 | Received 16746K total. 89 | Extracting zip contents 90 | Removing /Users/corning/local/elastic/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom 91 | Copying extracted folder /var/folders/mg/pxtj807539j2bbfwcmfprsw80000gn/T/phantomjs/phantomjs-2.1.1-macosx.zip-extract-1519609948869/phantomjs-2.1.1-macosx -> /Users/corning/local/elastic/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom 92 | Writing location.js file 93 | Done. Phantomjs binary available at /Users/corning/local/elastic/elasticsearch-head/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs 94 | elasticsearch-head@0.0.0 /Users/corning/local/elastic/elasticsearch-head 95 | ├─┬ grunt@1.0.1 96 | │ ├── coffee-script@1.10.0 97 | │ ├─┬ dateformat@1.0.12 98 | │ │ ├── get-stdin@4.0.1 99 | │ │ └─┬ meow@3.7.0 100 | │ │ ├─┬ camelcase-keys@2.1.0 101 | │ │ │ └── camelcase@2.1.1 102 | │ │ ├── decamelize@1.2.0 103 | │ │ ├─┬ loud-rejection@1.6.0 104 | │ │ │ ├─┬ currently-unhandled@0.4.1 105 | │ │ │ │ └── array-find-index@1.0.2 106 | │ │ │ └── signal-exit@3.0.2 107 | │ │ ├── map-obj@1.0.1 108 | │ │ ├── minimist@1.2.0 109 | │ │ ├─┬ normalize-package-data@2.4.0 110 | │ │ │ ├── hosted-git-info@2.5.0 111 | │ │ │ ├─┬ is-builtin-module@1.0.0 112 | │ │ │ │ └── builtin-modules@1.1.1 113 | │ │ │ └─┬ validate-npm-package-license@3.0.1 114 | │ │ │ ├─┬ spdx-correct@1.0.2 115 | │ │ │ │ └── spdx-license-ids@1.2.2 116 | │ │ │ └── spdx-expression-parse@1.0.4 117 | │ │ ├─┬ read-pkg-up@1.0.1 118 | │ │ │ ├─┬ find-up@1.1.2 119 | │ │ │ │ └── path-exists@2.1.0 120 | │ │ │ └─┬ read-pkg@1.1.0 121 | │ │ │ ├─┬ load-json-file@1.1.0 122 | │ │ │ │ ├─┬ parse-json@2.2.0 123 | │ │ │ │ │ └─┬ error-ex@1.3.1 124 | │ │ │ │ │ └── is-arrayish@0.2.1 125 | │ │ │ │ ├── pify@2.3.0 126 | │ │ │ │ └─┬ strip-bom@2.0.0 127 | │ │ │ │ └── is-utf8@0.2.1 128 | │ │ │ └── path-type@1.1.0 129 | │ │ ├─┬ redent@1.0.0 130 | │ │ │ ├─┬ indent-string@2.1.0 131 | │ │ │ │ └─┬ repeating@2.0.1 132 | │ │ │ │ └─┬ is-finite@1.0.2 133 | │ │ │ │ └── number-is-nan@1.0.1 134 | │ │ │ └── strip-indent@1.0.1 135 | │ │ └── trim-newlines@1.0.0 136 | │ ├── eventemitter2@0.4.14 137 | │ ├── exit@0.1.2 138 | │ ├─┬ findup-sync@0.3.0 139 | │ │ └── glob@5.0.15 140 | │ ├─┬ glob@7.0.6 141 | │ │ ├── fs.realpath@1.0.0 142 | │ │ ├─┬ inflight@1.0.6 143 | │ │ │ └── wrappy@1.0.2 144 | │ │ ├── inherits@2.0.3 145 | │ │ └── once@1.4.0 146 | │ ├─┬ grunt-cli@1.2.0 147 | │ │ └── resolve@1.1.7 148 | │ ├── grunt-known-options@1.1.0 149 | │ ├─┬ grunt-legacy-log@1.0.0 150 | │ │ ├─┬ grunt-legacy-log-utils@1.0.0 151 | │ │ │ └── lodash@4.3.0 152 | │ │ ├── hooker@0.2.3 153 | │ │ └── underscore.string@3.2.3 154 | │ ├─┬ grunt-legacy-util@1.0.0 155 | │ │ ├── getobject@0.1.0 156 | │ │ ├── lodash@4.3.0 157 | │ │ └─┬ which@1.2.14 158 | │ │ └── isexe@2.0.0 159 | │ ├── iconv-lite@0.4.19 160 | │ ├─┬ js-yaml@3.5.5 161 | │ │ ├── argparse@1.0.10 162 | │ │ └── esprima@2.7.3 163 | │ ├─┬ minimatch@3.0.4 164 | │ │ └─┬ brace-expansion@1.1.11 165 | │ │ ├── balanced-match@1.0.0 166 | │ │ └── concat-map@0.0.1 167 | │ ├─┬ nopt@3.0.6 168 | │ │ └── abbrev@1.1.1 169 | │ ├── path-is-absolute@1.0.1 170 | │ └── rimraf@2.2.8 171 | ├─┬ grunt-contrib-clean@1.0.0 172 | │ ├── async@1.5.2 173 | │ └── rimraf@2.6.2 174 | ├─┬ grunt-contrib-concat@1.0.1 175 | │ ├─┬ chalk@1.1.3 176 | │ │ ├── ansi-styles@2.2.1 177 | │ │ ├── escape-string-regexp@1.0.5 178 | │ │ ├─┬ has-ansi@2.0.0 179 | │ │ │ └── ansi-regex@2.1.1 180 | │ │ ├── strip-ansi@3.0.1 181 | │ │ └── supports-color@2.0.0 182 | │ └── source-map@0.5.7 183 | ├─┬ grunt-contrib-connect@1.0.2 184 | │ ├─┬ connect@3.6.6 185 | │ │ ├─┬ debug@2.6.9 186 | │ │ │ └── ms@2.0.0 187 | │ │ ├─┬ finalhandler@1.1.0 188 | │ │ │ ├── statuses@1.3.1 189 | │ │ │ └── unpipe@1.0.0 190 | │ │ ├── parseurl@1.3.2 191 | │ │ └── utils-merge@1.0.1 192 | │ ├── connect-livereload@0.5.4 193 | │ ├── http2@3.3.7 194 | │ ├─┬ morgan@1.9.0 195 | │ │ ├─┬ basic-auth@2.0.0 196 | │ │ │ └── safe-buffer@5.1.1 197 | │ │ ├── depd@1.1.2 198 | │ │ ├─┬ on-finished@2.3.0 199 | │ │ │ └── ee-first@1.1.1 200 | │ │ └── on-headers@1.0.1 201 | │ ├─┬ opn@4.0.2 202 | │ │ ├── object-assign@4.1.1 203 | │ │ └─┬ pinkie-promise@2.0.1 204 | │ │ └── pinkie@2.0.4 205 | │ ├── portscanner@1.2.0 206 | │ ├─┬ serve-index@1.9.1 207 | │ │ ├─┬ accepts@1.3.4 208 | │ │ │ └── negotiator@0.6.1 209 | │ │ ├── batch@0.6.1 210 | │ │ ├── escape-html@1.0.3 211 | │ │ ├─┬ http-errors@1.6.2 212 | │ │ │ ├── depd@1.1.1 213 | │ │ │ └── setprototypeof@1.0.3 214 | │ │ └─┬ mime-types@2.1.18 215 | │ │ └── mime-db@1.33.0 216 | │ └─┬ serve-static@1.13.2 217 | │ ├── encodeurl@1.0.2 218 | │ └─┬ send@0.16.2 219 | │ ├── destroy@1.0.4 220 | │ ├── etag@1.8.1 221 | │ ├── fresh@0.5.2 222 | │ └── statuses@1.4.0 223 | ├─┬ grunt-contrib-copy@1.0.0 224 | │ └── file-sync-cmp@0.1.1 225 | ├─┬ grunt-contrib-jasmine@1.0.3 226 | │ ├── es5-shim@4.5.10 227 | │ ├─┬ grunt-lib-phantomjs@1.1.0 228 | │ │ ├─┬ phantomjs-prebuilt@2.1.16 229 | │ │ │ ├── es6-promise@4.2.4 230 | │ │ │ ├─┬ extract-zip@1.6.6 231 | │ │ │ │ ├─┬ concat-stream@1.6.0 232 | │ │ │ │ │ └── typedarray@0.0.6 233 | │ │ │ │ ├─┬ mkdirp@0.5.0 234 | │ │ │ │ │ └── minimist@0.0.8 235 | │ │ │ │ └─┬ yauzl@2.4.1 236 | │ │ │ │ └─┬ fd-slicer@1.0.1 237 | │ │ │ │ └── pend@1.2.0 238 | │ │ │ ├─┬ fs-extra@1.0.0 239 | │ │ │ │ ├── jsonfile@2.4.0 240 | │ │ │ │ └── klaw@1.3.1 241 | │ │ │ ├─┬ hasha@2.2.0 242 | │ │ │ │ └── is-stream@1.1.0 243 | │ │ │ ├── kew@0.7.0 244 | │ │ │ ├── progress@1.1.8 245 | │ │ │ ├─┬ request@2.83.0 246 | │ │ │ │ ├── aws-sign2@0.7.0 247 | │ │ │ │ ├── aws4@1.6.0 248 | │ │ │ │ ├── caseless@0.12.0 249 | │ │ │ │ ├─┬ combined-stream@1.0.6 250 | │ │ │ │ │ └── delayed-stream@1.0.0 251 | │ │ │ │ ├── forever-agent@0.6.1 252 | │ │ │ │ ├─┬ form-data@2.3.2 253 | │ │ │ │ │ └── asynckit@0.4.0 254 | │ │ │ │ ├─┬ har-validator@5.0.3 255 | │ │ │ │ │ ├─┬ ajv@5.5.2 256 | │ │ │ │ │ │ ├── co@4.6.0 257 | │ │ │ │ │ │ ├── fast-deep-equal@1.1.0 258 | │ │ │ │ │ │ ├── fast-json-stable-stringify@2.0.0 259 | │ │ │ │ │ │ └── json-schema-traverse@0.3.1 260 | │ │ │ │ │ └── har-schema@2.0.0 261 | │ │ │ │ ├─┬ hawk@6.0.2 262 | │ │ │ │ │ ├── boom@4.3.1 263 | │ │ │ │ │ ├─┬ cryptiles@3.1.2 264 | │ │ │ │ │ │ └── boom@5.2.0 265 | │ │ │ │ │ ├── hoek@4.2.1 266 | │ │ │ │ │ └── sntp@2.1.0 267 | │ │ │ │ ├─┬ http-signature@1.2.0 268 | │ │ │ │ │ ├── assert-plus@1.0.0 269 | │ │ │ │ │ ├─┬ jsprim@1.4.1 270 | │ │ │ │ │ │ ├── extsprintf@1.3.0 271 | │ │ │ │ │ │ ├── json-schema@0.2.3 272 | │ │ │ │ │ │ └── verror@1.10.0 273 | │ │ │ │ │ └─┬ sshpk@1.13.1 274 | │ │ │ │ │ ├── asn1@0.2.3 275 | │ │ │ │ │ ├── bcrypt-pbkdf@1.0.1 276 | │ │ │ │ │ ├── dashdash@1.14.1 277 | │ │ │ │ │ ├── ecc-jsbn@0.1.1 278 | │ │ │ │ │ ├── getpass@0.1.7 279 | │ │ │ │ │ ├── jsbn@0.1.1 280 | │ │ │ │ │ └── tweetnacl@0.14.5 281 | │ │ │ │ ├── is-typedarray@1.0.0 282 | │ │ │ │ ├── isstream@0.1.2 283 | │ │ │ │ ├── json-stringify-safe@5.0.1 284 | │ │ │ │ ├── oauth-sign@0.8.2 285 | │ │ │ │ ├── performance-now@2.1.0 286 | │ │ │ │ ├── qs@6.5.1 287 | │ │ │ │ ├── stringstream@0.0.5 288 | │ │ │ │ ├─┬ tough-cookie@2.3.3 289 | │ │ │ │ │ └── punycode@1.4.1 290 | │ │ │ │ ├── tunnel-agent@0.6.0 291 | │ │ │ │ └── uuid@3.2.1 292 | │ │ │ └─┬ request-progress@2.0.1 293 | │ │ │ └── throttleit@1.0.0 294 | │ │ ├── rimraf@2.6.2 295 | │ │ ├── semver@5.5.0 296 | │ │ └─┬ temporary@0.0.8 297 | │ │ └── package@1.0.1 298 | │ ├── jasmine-core@2.99.1 299 | │ ├── lodash@2.4.2 300 | │ └── sprintf-js@1.0.3 301 | ├─┬ grunt-contrib-watch@1.0.0 302 | │ ├─┬ gaze@1.1.2 303 | │ │ └─┬ globule@1.2.0 304 | │ │ ├── glob@7.1.2 305 | │ │ └── lodash@4.17.5 306 | │ ├── lodash@3.10.1 307 | │ └─┬ tiny-lr@0.2.1 308 | │ ├─┬ debug@2.2.0 309 | │ │ └── ms@0.7.1 310 | │ ├─┬ faye-websocket@0.10.0 311 | │ │ └─┬ websocket-driver@0.7.0 312 | │ │ ├── http-parser-js@0.4.10 313 | │ │ └── websocket-extensions@0.1.3 314 | │ ├── livereload-js@2.3.0 315 | │ └── qs@5.1.0 316 | ├── grunt-karma@2.0.0 317 | ├─┬ http-proxy@1.16.2 318 | │ ├── eventemitter3@1.2.0 319 | │ └── requires-port@1.0.0 320 | └─┬ karma@1.3.0 321 | ├── bluebird@3.5.1 322 | ├─┬ body-parser@1.14.2 323 | │ ├── bytes@2.2.0 324 | │ ├── content-type@1.0.4 325 | │ ├─┬ debug@2.2.0 326 | │ │ └── ms@0.7.1 327 | │ ├── http-errors@1.3.1 328 | │ ├── iconv-lite@0.4.13 329 | │ ├── qs@5.2.0 330 | │ ├─┬ raw-body@2.1.7 331 | │ │ ├── bytes@2.4.0 332 | │ │ └── iconv-lite@0.4.13 333 | │ └─┬ type-is@1.6.16 334 | │ └── media-typer@0.3.0 335 | ├─┬ chokidar@1.7.0 336 | │ ├─┬ anymatch@1.3.2 337 | │ │ ├─┬ micromatch@2.3.11 338 | │ │ │ ├─┬ arr-diff@2.0.0 339 | │ │ │ │ └── arr-flatten@1.1.0 340 | │ │ │ ├─┬ braces@1.8.5 341 | │ │ │ │ ├─┬ expand-range@1.8.2 342 | │ │ │ │ │ └─┬ fill-range@2.2.3 343 | │ │ │ │ │ ├── is-number@2.1.0 344 | │ │ │ │ │ ├── isobject@2.1.0 345 | │ │ │ │ │ ├─┬ randomatic@1.1.7 346 | │ │ │ │ │ │ ├─┬ is-number@3.0.0 347 | │ │ │ │ │ │ │ └── kind-of@3.2.2 348 | │ │ │ │ │ │ └── kind-of@4.0.0 349 | │ │ │ │ │ └── repeat-string@1.6.1 350 | │ │ │ │ ├── preserve@0.2.0 351 | │ │ │ │ └── repeat-element@1.1.2 352 | │ │ │ ├─┬ expand-brackets@0.1.5 353 | │ │ │ │ └── is-posix-bracket@0.1.1 354 | │ │ │ ├── extglob@0.3.2 355 | │ │ │ ├── filename-regex@2.0.1 356 | │ │ │ ├─┬ kind-of@3.2.2 357 | │ │ │ │ └── is-buffer@1.1.6 358 | │ │ │ ├─┬ object.omit@2.0.1 359 | │ │ │ │ ├─┬ for-own@0.1.5 360 | │ │ │ │ │ └── for-in@1.0.2 361 | │ │ │ │ └── is-extendable@0.1.1 362 | │ │ │ ├─┬ parse-glob@3.0.4 363 | │ │ │ │ ├── glob-base@0.3.0 364 | │ │ │ │ └── is-dotfile@1.0.3 365 | │ │ │ └─┬ regex-cache@0.4.4 366 | │ │ │ └─┬ is-equal-shallow@0.1.3 367 | │ │ │ └── is-primitive@2.0.0 368 | │ │ └─┬ normalize-path@2.1.1 369 | │ │ └── remove-trailing-separator@1.1.0 370 | │ ├── async-each@1.0.1 371 | │ ├─┬ fsevents@1.1.3 372 | │ │ ├── nan@2.9.2 373 | │ │ └─┬ node-pre-gyp@0.6.39 374 | │ │ ├── detect-libc@1.0.2 375 | │ │ ├─┬ hawk@3.1.3 376 | │ │ │ ├── boom@2.10.1 377 | │ │ │ ├── cryptiles@2.0.5 378 | │ │ │ ├── hoek@2.16.3 379 | │ │ │ └── sntp@1.0.9 380 | │ │ ├─┬ mkdirp@0.5.1 381 | │ │ │ └── minimist@0.0.8 382 | │ │ ├─┬ nopt@4.0.1 383 | │ │ │ ├── abbrev@1.1.0 384 | │ │ │ └─┬ osenv@0.1.4 385 | │ │ │ ├── os-homedir@1.0.2 386 | │ │ │ └── os-tmpdir@1.0.2 387 | │ │ ├─┬ npmlog@4.1.0 388 | │ │ │ ├─┬ are-we-there-yet@1.1.4 389 | │ │ │ │ └── delegates@1.0.0 390 | │ │ │ ├── console-control-strings@1.1.0 391 | │ │ │ ├─┬ gauge@2.7.4 392 | │ │ │ │ ├── aproba@1.1.1 393 | │ │ │ │ ├── has-unicode@2.0.1 394 | │ │ │ │ ├── object-assign@4.1.1 395 | │ │ │ │ ├── signal-exit@3.0.2 396 | │ │ │ │ ├─┬ string-width@1.0.2 397 | │ │ │ │ │ ├── code-point-at@1.1.0 398 | │ │ │ │ │ └─┬ is-fullwidth-code-point@1.0.0 399 | │ │ │ │ │ └── number-is-nan@1.0.1 400 | │ │ │ │ ├─┬ strip-ansi@3.0.1 401 | │ │ │ │ │ └── ansi-regex@2.1.1 402 | │ │ │ │ └── wide-align@1.1.2 403 | │ │ │ └── set-blocking@2.0.0 404 | │ │ ├─┬ rc@1.2.1 405 | │ │ │ ├── deep-extend@0.4.2 406 | │ │ │ ├── ini@1.3.4 407 | │ │ │ ├── minimist@1.2.0 408 | │ │ │ └── strip-json-comments@2.0.1 409 | │ │ ├─┬ request@2.81.0 410 | │ │ │ ├── aws-sign2@0.6.0 411 | │ │ │ ├── aws4@1.6.0 412 | │ │ │ ├── caseless@0.12.0 413 | │ │ │ ├─┬ combined-stream@1.0.5 414 | │ │ │ │ └── delayed-stream@1.0.0 415 | │ │ │ ├── extend@3.0.1 416 | │ │ │ ├── forever-agent@0.6.1 417 | │ │ │ ├─┬ form-data@2.1.4 418 | │ │ │ │ └── asynckit@0.4.0 419 | │ │ │ ├─┬ har-validator@4.2.1 420 | │ │ │ │ ├─┬ ajv@4.11.8 421 | │ │ │ │ │ ├── co@4.6.0 422 | │ │ │ │ │ └─┬ json-stable-stringify@1.0.1 423 | │ │ │ │ │ └── jsonify@0.0.0 424 | │ │ │ │ └── har-schema@1.0.5 425 | │ │ │ ├─┬ http-signature@1.1.1 426 | │ │ │ │ ├── assert-plus@0.2.0 427 | │ │ │ │ ├─┬ jsprim@1.4.0 428 | │ │ │ │ │ ├── assert-plus@1.0.0 429 | │ │ │ │ │ ├── extsprintf@1.0.2 430 | │ │ │ │ │ ├── json-schema@0.2.3 431 | │ │ │ │ │ └── verror@1.3.6 432 | │ │ │ │ └─┬ sshpk@1.13.0 433 | │ │ │ │ ├── asn1@0.2.3 434 | │ │ │ │ ├── assert-plus@1.0.0 435 | │ │ │ │ ├── bcrypt-pbkdf@1.0.1 436 | │ │ │ │ ├─┬ dashdash@1.14.1 437 | │ │ │ │ │ └── assert-plus@1.0.0 438 | │ │ │ │ ├── ecc-jsbn@0.1.1 439 | │ │ │ │ ├─┬ getpass@0.1.7 440 | │ │ │ │ │ └── assert-plus@1.0.0 441 | │ │ │ │ ├── jodid25519@1.0.2 442 | │ │ │ │ ├── jsbn@0.1.1 443 | │ │ │ │ └── tweetnacl@0.14.5 444 | │ │ │ ├── is-typedarray@1.0.0 445 | │ │ │ ├── isstream@0.1.2 446 | │ │ │ ├── json-stringify-safe@5.0.1 447 | │ │ │ ├─┬ mime-types@2.1.15 448 | │ │ │ │ └── mime-db@1.27.0 449 | │ │ │ ├── oauth-sign@0.8.2 450 | │ │ │ ├── performance-now@0.2.0 451 | │ │ │ ├── qs@6.4.0 452 | │ │ │ ├── safe-buffer@5.0.1 453 | │ │ │ ├── stringstream@0.0.5 454 | │ │ │ ├─┬ tough-cookie@2.3.2 455 | │ │ │ │ └── punycode@1.4.1 456 | │ │ │ ├── tunnel-agent@0.6.0 457 | │ │ │ └── uuid@3.0.1 458 | │ │ ├─┬ rimraf@2.6.1 459 | │ │ │ └─┬ glob@7.1.2 460 | │ │ │ ├── fs.realpath@1.0.0 461 | │ │ │ ├── inflight@1.0.6 462 | │ │ │ ├─┬ minimatch@3.0.4 463 | │ │ │ │ └─┬ brace-expansion@1.1.7 464 | │ │ │ │ ├── balanced-match@0.4.2 465 | │ │ │ │ └── concat-map@0.0.1 466 | │ │ │ └── path-is-absolute@1.0.1 467 | │ │ ├── semver@5.3.0 468 | │ │ ├─┬ tar@2.2.1 469 | │ │ │ ├── block-stream@0.0.9 470 | │ │ │ ├─┬ fstream@1.0.11 471 | │ │ │ │ └── graceful-fs@4.1.11 472 | │ │ │ └── inherits@2.0.3 473 | │ │ └─┬ tar-pack@3.4.0 474 | │ │ ├─┬ debug@2.6.8 475 | │ │ │ └── ms@2.0.0 476 | │ │ ├── fstream-ignore@1.0.5 477 | │ │ ├─┬ once@1.4.0 478 | │ │ │ └── wrappy@1.0.2 479 | │ │ ├─┬ readable-stream@2.2.9 480 | │ │ │ ├── buffer-shims@1.0.0 481 | │ │ │ ├── core-util-is@1.0.2 482 | │ │ │ ├── isarray@1.0.0 483 | │ │ │ ├── process-nextick-args@1.0.7 484 | │ │ │ ├── string_decoder@1.0.1 485 | │ │ │ └── util-deprecate@1.0.2 486 | │ │ └── uid-number@0.0.6 487 | │ ├── glob-parent@2.0.0 488 | │ ├─┬ is-binary-path@1.0.1 489 | │ │ └── binary-extensions@1.11.0 490 | │ ├─┬ is-glob@2.0.1 491 | │ │ └── is-extglob@1.0.0 492 | │ └─┬ readdirp@2.1.0 493 | │ ├─┬ readable-stream@2.3.4 494 | │ │ ├── isarray@1.0.0 495 | │ │ ├── process-nextick-args@2.0.0 496 | │ │ ├── string_decoder@1.0.3 497 | │ │ └── util-deprecate@1.0.2 498 | │ └── set-immediate-shim@1.0.1 499 | ├── colors@1.1.2 500 | ├─┬ combine-lists@1.0.1 501 | │ └── lodash@4.17.5 502 | ├── core-js@2.5.3 503 | ├── di@0.0.1 504 | ├─┬ dom-serialize@2.2.1 505 | │ ├── custom-event@1.0.1 506 | │ ├── ent@2.2.0 507 | │ ├── extend@3.0.1 508 | │ └── void-elements@2.0.1 509 | ├─┬ expand-braces@0.1.2 510 | │ ├── array-slice@0.2.3 511 | │ ├── array-unique@0.2.1 512 | │ └─┬ braces@0.1.5 513 | │ └─┬ expand-range@0.1.1 514 | │ ├── is-number@0.1.1 515 | │ └── repeat-string@0.2.2 516 | ├── graceful-fs@4.1.11 517 | ├── isbinaryfile@3.0.2 518 | ├─┬ log4js@0.6.38 519 | │ ├─┬ readable-stream@1.0.34 520 | │ │ ├── core-util-is@1.0.2 521 | │ │ ├── isarray@0.0.1 522 | │ │ └── string_decoder@0.10.31 523 | │ └── semver@4.3.6 524 | ├── mime@1.4.1 525 | ├─┬ optimist@0.6.1 526 | │ ├── minimist@0.0.10 527 | │ └── wordwrap@0.0.3 528 | ├── qjobs@1.2.0 529 | ├── range-parser@1.2.0 530 | ├── rimraf@2.6.2 531 | ├─┬ socket.io@1.4.7 532 | │ ├─┬ debug@2.2.0 533 | │ │ └── ms@0.7.1 534 | │ ├─┬ engine.io@1.6.10 535 | │ │ ├─┬ accepts@1.1.4 536 | │ │ │ ├─┬ mime-types@2.0.14 537 | │ │ │ │ └── mime-db@1.12.0 538 | │ │ │ └── negotiator@0.4.9 539 | │ │ ├── base64id@0.1.0 540 | │ │ ├─┬ debug@2.2.0 541 | │ │ │ └── ms@0.7.1 542 | │ │ ├─┬ engine.io-parser@1.2.4 543 | │ │ │ ├── after@0.8.1 544 | │ │ │ ├── arraybuffer.slice@0.0.6 545 | │ │ │ ├── base64-arraybuffer@0.1.2 546 | │ │ │ ├── blob@0.0.4 547 | │ │ │ ├─┬ has-binary@0.1.6 548 | │ │ │ │ └── isarray@0.0.1 549 | │ │ │ └── utf8@2.1.0 550 | │ │ └─┬ ws@1.0.1 551 | │ │ ├── options@0.0.6 552 | │ │ └── ultron@1.0.2 553 | │ ├─┬ has-binary@0.1.7 554 | │ │ └── isarray@0.0.1 555 | │ ├─┬ socket.io-adapter@0.4.0 556 | │ │ ├─┬ debug@2.2.0 557 | │ │ │ └── ms@0.7.1 558 | │ │ └─┬ socket.io-parser@2.2.2 559 | │ │ ├── debug@0.7.4 560 | │ │ ├── isarray@0.0.1 561 | │ │ └── json3@3.2.6 562 | │ ├─┬ socket.io-client@1.4.6 563 | │ │ ├── backo2@1.0.2 564 | │ │ ├── component-bind@1.0.0 565 | │ │ ├── component-emitter@1.2.0 566 | │ │ ├─┬ debug@2.2.0 567 | │ │ │ └── ms@0.7.1 568 | │ │ ├─┬ engine.io-client@1.6.9 569 | │ │ │ ├── component-inherit@0.0.3 570 | │ │ │ ├─┬ debug@2.2.0 571 | │ │ │ │ └── ms@0.7.1 572 | │ │ │ ├── has-cors@1.1.0 573 | │ │ │ ├── parsejson@0.0.1 574 | │ │ │ ├── parseqs@0.0.2 575 | │ │ │ ├── xmlhttprequest-ssl@1.5.1 576 | # ======================== Elasticsearch Configuration ========================= 577 | # 578 | # NOTE: Elasticsearch comes with reasonable defaults for most settings. 579 | # Before you set out to tweak and tune the configuration, make sure you 580 | # understand what are you trying to accomplish and the consequences. 581 | # 582 | # The primary way of configuring a node is via this file. This template lists 583 | # the most important settings you may want to configure for a production cluster. 584 | # 585 | # Please consult the documentation for further information on configuration options: 586 | # https://www.elastic.co/guide/en/elasticsearch/reference/index.html 587 | # 588 | # ---------------------------------- Cluster ----------------------------------- 589 | # 590 | # Use a descriptive name for your cluster: 591 | # 592 | #cluster.name: my-application 593 | # 594 | # ------------------------------------ Node ------------------------------------ 595 | # 596 | # Use a descriptive name for the node: 597 | # 598 | #node.name: node-1 599 | # 600 | # Add custom attributes to the node: 601 | # 602 | #node.attr.rack: r1 603 | # 604 | # ----------------------------------- Paths ------------------------------------ 605 | # 606 | # Path to directory where to store the data (separate multiple locations by comma): 607 | # 608 | #path.data: /path/to/data 609 | # 610 | # Path to log files: 611 | # 612 | #path.logs: /path/to/logs 613 | # 614 | # ----------------------------------- Memory ----------------------------------- 615 | "config/elasticsearch.yml" 88L, 2853C 616 | # Set the bind address to a specific IP (IPv4 or IPv6): 617 | │ │ │ └── yeast@0.1.2 618 | │ │ ├── indexof@0.0.1 619 | │ │ ├── object-component@0.0.3 620 | │ │ ├─┬ parseuri@0.0.4 621 | │ │ │ └─┬ better-assert@1.0.2 622 | │ │ │ └── callsite@1.0.0 623 | │ │ └── to-array@0.1.4 624 | │ └─┬ socket.io-parser@2.2.6 625 | │ ├── benchmark@1.0.0 626 | │ ├── component-emitter@1.1.2 627 | │ ├─┬ debug@2.2.0 628 | │ │ └── ms@0.7.1 629 | │ ├── isarray@0.0.1 630 | │ └── json3@3.3.2 631 | ├─┬ tmp@0.0.28 632 | │ └── os-tmpdir@1.0.2 633 | └─┬ useragent@2.3.0 634 | └─┬ lru-cache@4.1.1 635 | ├── pseudomap@1.0.2 636 | └── yallist@2.1.2 637 | 638 | npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression 639 | CorningSunMac:elasticsearch-head corning$ npm run start 640 | 641 | > elasticsearch-head@0.0.0 start /Users/corning/local/elastic/elasticsearch-head 642 | > grunt server 643 | 644 | Running "connect:server" (connect) task 645 | Waiting forever... 646 | Started connect web server on http://localhost:9100 647 | ^C 648 | CorningSunMac:elasticsearch-head corning$ cd ../elasticsearch-6.2.2 649 | CorningSunMac:elasticsearch-6.2.2 corning$ ls 650 | LICENSE.txt NOTICE.txt README.textile bin config data lib logs modules plugins 651 | CorningSunMac:elasticsearch-6.2.2 corning$ vi config/elasticsearch.yml 652 | CorningSunMac:elasticsearch-6.2.2 corning$ ./bin/elasticsearch -d 653 | CorningSunMac:elasticsearch-6.2.2 corning$ Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. 654 | cd .. 655 | CorningSunMac:elastic corning$ ls 656 | elasticsearch-6.2.2 elasticsearch-6.2.2.tar.gz elasticsearch-head 657 | CorningSunMac:elastic corning$ cd elasticsearch-head/ 658 | CorningSunMac:elasticsearch-head corning$ npm run start 659 | 660 | > elasticsearch-head@0.0.0 start /Users/corning/local/elastic/elasticsearch-head 661 | > grunt server 662 | 663 | Running "connect:server" (connect) task 664 | Waiting forever... 665 | Started connect web server on http://localhost:9100 666 | 667 | ``` -------------------------------------------------------------------------------- /doc/2-4_分布式安装.md: -------------------------------------------------------------------------------- 1 | # 2-4 分布式安装 2 | 3 | ## 配置 master 4 | 5 | ``` 6 | cluster.name: corning 7 | node.name: master 8 | node.master: true 9 | 10 | network.host: 127.0.0.1 11 | ``` 12 | 13 | ## 配置 slave1 14 | 15 | ``` 16 | cluster.name: corning 17 | node.name: slave1 18 | 19 | network.host: 127.0.0.1 20 | http.port: 9201 21 | 22 | discovery.zen.ping.unicast.hosts: ["127.0.0.1"] 23 | ``` 24 | 25 | ## 配置 slave2 26 | 27 | ``` 28 | cluster.name: corning 29 | node.name: slave2 30 | 31 | network.host: 127.0.0.1 32 | http.port: 9202 33 | 34 | discovery.zen.ping.unicast.hosts: ["127.0.0.1"] 35 | ``` 36 | 37 | ## 检查结果 38 | 39 | ![](./img/elasticsearch-head_cluster.png) 40 | 41 | ## 详细步骤 42 | 43 | ### 配置 master 44 | 45 | ``` 46 | CorningSunMac:elasticsearch-6.2.2 corning$ ps -ef | grep `pwd` 47 | 501 11449 1 0 9:55上午 ttys003 0:23.50 /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home//bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/var/folders/mg/pxtj807539j2bbfwcmfprsw80000gn/T/elasticsearch.OCepUNRf -XX:+HeapDumpOnOutOfMemoryError -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -Djava.locale.providers=COMPAT -Des.path.home=/Users/corning/local/elastic/elasticsearch-6.2.2 -Des.path.conf=/Users/corning/local/elastic/elasticsearch-6.2.2/config -cp /Users/corning/local/elastic/elasticsearch-6.2.2/lib/* org.elasticsearch.bootstrap.Elasticsearch -d 48 | 501 11718 11664 0 10:15上午 ttys004 0:00.00 grep /Users/corning/local/elastic/elasticsearch-6.2.2 49 | CorningSunMac:elasticsearch-6.2.2 corning$ kill -9 11449 50 | CorningSunMac:elasticsearch-6.2.2 corning$ ps -ef | grep `pwd` 51 | 501 11726 11664 0 10:16上午 ttys004 0:00.00 grep /Users/corning/local/elastic/elasticsearch-6.2.2 52 | CorningSunMac:elasticsearch-6.2.2 corning$ vi config/elasticsearch.yml 53 | CorningSunMac:elasticsearch-6.2.2 corning$ ./bin/elasticsearch 54 | Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. 55 | [2018-02-26T10:17:36,153][INFO ][o.e.n.Node ] [master] initializing ... 56 | [2018-02-26T10:17:36,235][INFO ][o.e.e.NodeEnvironment ] [master] using [1] data paths, mounts [[/ (/dev/disk1s1)]], net usable_space [109.6gb], net total_space [465.7gb], types [apfs] 57 | [2018-02-26T10:17:36,235][INFO ][o.e.e.NodeEnvironment ] [master] heap size [989.8mb], compressed ordinary object pointers [true] 58 | [2018-02-26T10:17:36,237][INFO ][o.e.n.Node ] [master] node name [master], node ID [mF4GZ8u0T8eKC8iHNzTt_w] 59 | [2018-02-26T10:17:36,237][INFO ][o.e.n.Node ] [master] version[6.2.2], pid[11737], build[10b1edd/2018-02-16T19:01:30.685723Z], OS[Mac OS X/10.13.3/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/9/9+181] 60 | [2018-02-26T10:17:36,238][INFO ][o.e.n.Node ] [master] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/var/folders/mg/pxtj807539j2bbfwcmfprsw80000gn/T/elasticsearch.aLocBnrM, -XX:+HeapDumpOnOutOfMemoryError, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Djava.locale.providers=COMPAT, -Des.path.home=/Users/corning/local/elastic/elasticsearch-6.2.2, -Des.path.conf=/Users/corning/local/elastic/elasticsearch-6.2.2/config] 61 | [2018-02-26T10:17:36,668][INFO ][o.e.p.PluginsService ] [master] loaded module [aggs-matrix-stats] 62 | [2018-02-26T10:17:36,669][INFO ][o.e.p.PluginsService ] [master] loaded module [analysis-common] 63 | [2018-02-26T10:17:36,669][INFO ][o.e.p.PluginsService ] [master] loaded module [ingest-common] 64 | [2018-02-26T10:17:36,669][INFO ][o.e.p.PluginsService ] [master] loaded module [lang-expression] 65 | [2018-02-26T10:17:36,669][INFO ][o.e.p.PluginsService ] [master] loaded module [lang-mustache] 66 | [2018-02-26T10:17:36,669][INFO ][o.e.p.PluginsService ] [master] loaded module [lang-painless] 67 | [2018-02-26T10:17:36,669][INFO ][o.e.p.PluginsService ] [master] loaded module [mapper-extras] 68 | [2018-02-26T10:17:36,669][INFO ][o.e.p.PluginsService ] [master] loaded module [parent-join] 69 | [2018-02-26T10:17:36,669][INFO ][o.e.p.PluginsService ] [master] loaded module [percolator] 70 | [2018-02-26T10:17:36,670][INFO ][o.e.p.PluginsService ] [master] loaded module [rank-eval] 71 | [2018-02-26T10:17:36,670][INFO ][o.e.p.PluginsService ] [master] loaded module [reindex] 72 | [2018-02-26T10:17:36,670][INFO ][o.e.p.PluginsService ] [master] loaded module [repository-url] 73 | [2018-02-26T10:17:36,670][INFO ][o.e.p.PluginsService ] [master] loaded module [transport-netty4] 74 | [2018-02-26T10:17:36,670][INFO ][o.e.p.PluginsService ] [master] loaded module [tribe] 75 | [2018-02-26T10:17:36,670][INFO ][o.e.p.PluginsService ] [master] no plugins loaded 76 | [2018-02-26T10:17:38,292][INFO ][o.e.d.DiscoveryModule ] [master] using discovery type [zen] 77 | [2018-02-26T10:17:38,694][INFO ][o.e.n.Node ] [master] initialized 78 | [2018-02-26T10:17:38,695][INFO ][o.e.n.Node ] [master] starting ... 79 | [2018-02-26T10:17:38,841][INFO ][o.e.t.TransportService ] [master] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300} 80 | [2018-02-26T10:17:41,890][INFO ][o.e.c.s.MasterService ] [master] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {master}{mF4GZ8u0T8eKC8iHNzTt_w}{x7mBUXVhRbiQ1GTgz8t3qw}{127.0.0.1}{127.0.0.1:9300} 81 | [2018-02-26T10:17:41,896][INFO ][o.e.c.s.ClusterApplierService] [master] new_master {master}{mF4GZ8u0T8eKC8iHNzTt_w}{x7mBUXVhRbiQ1GTgz8t3qw}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {master}{mF4GZ8u0T8eKC8iHNzTt_w}{x7mBUXVhRbiQ1GTgz8t3qw}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]]) 82 | [2018-02-26T10:17:41,908][INFO ][o.e.h.n.Netty4HttpServerTransport] [master] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200} 83 | [2018-02-26T10:17:41,908][INFO ][o.e.n.Node ] [master] started 84 | [2018-02-26T10:17:41,940][INFO ][o.e.g.GatewayService ] [master] recovered [0] indices into cluster_state 85 | [2018-02-26T10:26:37,117][INFO ][o.e.c.s.MasterService ] [master] zen-disco-node-join[{slave1}{qLXbdcA1TdOTTpJfqKVwtg}{fvw7oN6kSvSY3psHu4q9cQ}{127.0.0.1}{127.0.0.1:9301}], reason: added {{slave1}{qLXbdcA1TdOTTpJfqKVwtg}{fvw7oN6kSvSY3psHu4q9cQ}{127.0.0.1}{127.0.0.1:9301},} 86 | [2018-02-26T10:26:37,169][INFO ][o.e.c.s.ClusterApplierService] [master] added {{slave1}{qLXbdcA1TdOTTpJfqKVwtg}{fvw7oN6kSvSY3psHu4q9cQ}{127.0.0.1}{127.0.0.1:9301},}, reason: apply cluster state (from master [master {master}{mF4GZ8u0T8eKC8iHNzTt_w}{x7mBUXVhRbiQ1GTgz8t3qw}{127.0.0.1}{127.0.0.1:9300} committed version [3] source [zen-disco-node-join[{slave1}{qLXbdcA1TdOTTpJfqKVwtg}{fvw7oN6kSvSY3psHu4q9cQ}{127.0.0.1}{127.0.0.1:9301}]]]) 87 | [2018-02-26T10:26:37,171][WARN ][o.e.d.z.ElectMasterService] [master] value for setting "discovery.zen.minimum_master_nodes" is too low. This can result in data loss! Please set it to at least a quorum of master-eligible nodes (current value: [-1], total number of master-eligible nodes used for publishing in this round: [2]) 88 | [2018-02-26T10:27:04,094][INFO ][o.e.c.s.MasterService ] [master] zen-disco-node-join[{slave2}{LFTX2kxBS9K4eB2AgSUaNg}{-HRWBruwTiCVYd0O0xTU7w}{127.0.0.1}{127.0.0.1:9302}], reason: added {{slave2}{LFTX2kxBS9K4eB2AgSUaNg}{-HRWBruwTiCVYd0O0xTU7w}{127.0.0.1}{127.0.0.1:9302},} 89 | [2018-02-26T10:27:04,190][INFO ][o.e.c.s.ClusterApplierService] [master] added {{slave2}{LFTX2kxBS9K4eB2AgSUaNg}{-HRWBruwTiCVYd0O0xTU7w}{127.0.0.1}{127.0.0.1:9302},}, reason: apply cluster state (from master [master {master}{mF4GZ8u0T8eKC8iHNzTt_w}{x7mBUXVhRbiQ1GTgz8t3qw}{127.0.0.1}{127.0.0.1:9300} committed version [4] source [zen-disco-node-join[{slave2}{LFTX2kxBS9K4eB2AgSUaNg}{-HRWBruwTiCVYd0O0xTU7w}{127.0.0.1}{127.0.0.1:9302}]]]) 90 | ``` 91 | 92 | ### 配置 slave1 93 | 94 | ``` 95 | CorningSunMac:~ corning$ cd local/elastic/ 96 | CorningSunMac:elastic corning$ ls 97 | elasticsearch-6.2.2 elasticsearch-6.2.2.tar.gz elasticsearch-head 98 | CorningSunMac:elastic corning$ mkdir es_slave 99 | CorningSunMac:elastic corning$ mv elasticsearch-6.2.2.tar.gz es_slave/ 100 | CorningSunMac:elastic corning$ ls 101 | elasticsearch-6.2.2 elasticsearch-head es_slave 102 | CorningSunMac:elastic corning$ cd es_slave/ 103 | CorningSunMac:es_slave corning$ ls 104 | elasticsearch-6.2.2.tar.gz 105 | CorningSunMac:es_slave corning$ tar -vxf elasticsearch-6.2.2.tar.gz 106 | x elasticsearch-6.2.2/ 107 | x elasticsearch-6.2.2/lib/ 108 | x elasticsearch-6.2.2/lib/elasticsearch-6.2.2.jar 109 | x elasticsearch-6.2.2/lib/elasticsearch-core-6.2.2.jar 110 | x elasticsearch-6.2.2/lib/lucene-core-7.2.1.jar 111 | x elasticsearch-6.2.2/lib/lucene-analyzers-common-7.2.1.jar 112 | x elasticsearch-6.2.2/lib/lucene-backward-codecs-7.2.1.jar 113 | x elasticsearch-6.2.2/lib/lucene-grouping-7.2.1.jar 114 | x elasticsearch-6.2.2/lib/lucene-highlighter-7.2.1.jar 115 | x elasticsearch-6.2.2/lib/lucene-join-7.2.1.jar 116 | x elasticsearch-6.2.2/lib/lucene-memory-7.2.1.jar 117 | x elasticsearch-6.2.2/lib/lucene-misc-7.2.1.jar 118 | x elasticsearch-6.2.2/lib/lucene-queries-7.2.1.jar 119 | x elasticsearch-6.2.2/lib/lucene-queryparser-7.2.1.jar 120 | x elasticsearch-6.2.2/lib/lucene-sandbox-7.2.1.jar 121 | x elasticsearch-6.2.2/lib/lucene-spatial-7.2.1.jar 122 | x elasticsearch-6.2.2/lib/lucene-spatial-extras-7.2.1.jar 123 | x elasticsearch-6.2.2/lib/lucene-spatial3d-7.2.1.jar 124 | x elasticsearch-6.2.2/lib/lucene-suggest-7.2.1.jar 125 | x elasticsearch-6.2.2/lib/securesm-1.2.jar 126 | x elasticsearch-6.2.2/lib/hppc-0.7.1.jar 127 | x elasticsearch-6.2.2/lib/joda-time-2.9.9.jar 128 | x elasticsearch-6.2.2/lib/snakeyaml-1.17.jar 129 | x elasticsearch-6.2.2/lib/jackson-core-2.8.10.jar 130 | x elasticsearch-6.2.2/lib/jackson-dataformat-smile-2.8.10.jar 131 | x elasticsearch-6.2.2/lib/jackson-dataformat-yaml-2.8.10.jar 132 | x elasticsearch-6.2.2/lib/jackson-dataformat-cbor-2.8.10.jar 133 | x elasticsearch-6.2.2/lib/t-digest-3.0.jar 134 | x elasticsearch-6.2.2/lib/HdrHistogram-2.1.9.jar 135 | x elasticsearch-6.2.2/lib/spatial4j-0.6.jar 136 | x elasticsearch-6.2.2/lib/jts-1.13.jar 137 | x elasticsearch-6.2.2/lib/log4j-api-2.9.1.jar 138 | x elasticsearch-6.2.2/lib/log4j-core-2.9.1.jar 139 | x elasticsearch-6.2.2/lib/log4j-1.2-api-2.9.1.jar 140 | x elasticsearch-6.2.2/lib/jna-4.5.1.jar 141 | x elasticsearch-6.2.2/lib/elasticsearch-cli-6.2.2.jar 142 | x elasticsearch-6.2.2/lib/jopt-simple-5.0.2.jar 143 | x elasticsearch-6.2.2/lib/plugin-classloader-6.2.2.jar 144 | x elasticsearch-6.2.2/lib/elasticsearch-launchers-6.2.2.jar 145 | x elasticsearch-6.2.2/lib/plugin-cli-6.2.2.jar 146 | x elasticsearch-6.2.2/config/ 147 | x elasticsearch-6.2.2/config/elasticsearch.yml 148 | x elasticsearch-6.2.2/config/jvm.options 149 | x elasticsearch-6.2.2/config/log4j2.properties 150 | x elasticsearch-6.2.2/bin/ 151 | x elasticsearch-6.2.2/bin/elasticsearch-env 152 | x elasticsearch-6.2.2/bin/elasticsearch 153 | x elasticsearch-6.2.2/bin/elasticsearch-plugin 154 | x elasticsearch-6.2.2/bin/elasticsearch-translog 155 | x elasticsearch-6.2.2/bin/elasticsearch-keystore 156 | x elasticsearch-6.2.2/bin/elasticsearch-env.bat 157 | x elasticsearch-6.2.2/bin/elasticsearch-keystore.bat 158 | x elasticsearch-6.2.2/bin/elasticsearch-service.bat 159 | x elasticsearch-6.2.2/bin/elasticsearch.bat 160 | x elasticsearch-6.2.2/bin/elasticsearch-translog.bat 161 | x elasticsearch-6.2.2/bin/elasticsearch-plugin.bat 162 | x elasticsearch-6.2.2/README.textile 163 | x elasticsearch-6.2.2/LICENSE.txt 164 | x elasticsearch-6.2.2/NOTICE.txt 165 | x elasticsearch-6.2.2/bin/elasticsearch-service-mgr.exe 166 | x elasticsearch-6.2.2/bin/elasticsearch-service-x64.exe 167 | x elasticsearch-6.2.2/modules/ 168 | x elasticsearch-6.2.2/modules/reindex/ 169 | x elasticsearch-6.2.2/modules/reindex/reindex-6.2.2.jar 170 | x elasticsearch-6.2.2/modules/reindex/httpcore-4.4.5.jar 171 | x elasticsearch-6.2.2/modules/reindex/httpcore-nio-4.4.5.jar 172 | x elasticsearch-6.2.2/modules/reindex/plugin-security.policy 173 | x elasticsearch-6.2.2/modules/reindex/elasticsearch-rest-client-6.2.2.jar 174 | x elasticsearch-6.2.2/modules/reindex/commons-logging-1.1.3.jar 175 | x elasticsearch-6.2.2/modules/reindex/httpasyncclient-4.1.2.jar 176 | x elasticsearch-6.2.2/modules/reindex/plugin-descriptor.properties 177 | x elasticsearch-6.2.2/modules/reindex/httpclient-4.5.2.jar 178 | x elasticsearch-6.2.2/modules/reindex/commons-codec-1.10.jar 179 | x elasticsearch-6.2.2/modules/rank-eval/ 180 | x elasticsearch-6.2.2/modules/rank-eval/rank-eval-6.2.2.jar 181 | x elasticsearch-6.2.2/modules/rank-eval/plugin-descriptor.properties 182 | x elasticsearch-6.2.2/modules/lang-painless/ 183 | x elasticsearch-6.2.2/modules/lang-painless/antlr4-runtime-4.5.3.jar 184 | x elasticsearch-6.2.2/modules/lang-painless/plugin-security.policy 185 | x elasticsearch-6.2.2/modules/lang-painless/lang-painless-6.2.2.jar 186 | x elasticsearch-6.2.2/modules/lang-painless/plugin-descriptor.properties 187 | x elasticsearch-6.2.2/modules/lang-painless/elasticsearch-scripting-painless-spi-6.2.2.jar 188 | x elasticsearch-6.2.2/modules/lang-painless/asm-debug-all-5.1.jar 189 | x elasticsearch-6.2.2/modules/repository-url/ 190 | x elasticsearch-6.2.2/modules/repository-url/plugin-security.policy 191 | x elasticsearch-6.2.2/modules/repository-url/plugin-descriptor.properties 192 | x elasticsearch-6.2.2/modules/repository-url/repository-url-6.2.2.jar 193 | x elasticsearch-6.2.2/modules/percolator/ 194 | x elasticsearch-6.2.2/modules/percolator/plugin-descriptor.properties 195 | x elasticsearch-6.2.2/modules/percolator/percolator-6.2.2.jar 196 | x elasticsearch-6.2.2/modules/tribe/ 197 | x elasticsearch-6.2.2/modules/tribe/tribe-6.2.2.jar 198 | x elasticsearch-6.2.2/modules/tribe/plugin-descriptor.properties 199 | x elasticsearch-6.2.2/modules/aggs-matrix-stats/ 200 | x elasticsearch-6.2.2/modules/aggs-matrix-stats/aggs-matrix-stats-6.2.2.jar 201 | x elasticsearch-6.2.2/modules/aggs-matrix-stats/plugin-descriptor.properties 202 | x elasticsearch-6.2.2/modules/transport-netty4/ 203 | x elasticsearch-6.2.2/modules/transport-netty4/netty-codec-4.1.16.Final.jar 204 | x elasticsearch-6.2.2/modules/transport-netty4/netty-buffer-4.1.16.Final.jar 205 | x elasticsearch-6.2.2/modules/transport-netty4/netty-common-4.1.16.Final.jar 206 | x elasticsearch-6.2.2/modules/transport-netty4/netty-codec-http-4.1.16.Final.jar 207 | x elasticsearch-6.2.2/modules/transport-netty4/transport-netty4-6.2.2.jar 208 | x elasticsearch-6.2.2/modules/transport-netty4/plugin-security.policy 209 | x elasticsearch-6.2.2/modules/transport-netty4/plugin-descriptor.properties 210 | x elasticsearch-6.2.2/modules/transport-netty4/netty-resolver-4.1.16.Final.jar 211 | # 212 | x elasticsearch-6.2.2/modules/transport-netty4/netty-transport-4.1.16.Final.jar 213 | x elasticsearch-6.2.2/modules/transport-netty4/netty-handler-4.1.16.Final.jar 214 | x elasticsearch-6.2.2/modules/ingest-common/ 215 | x elasticsearch-6.2.2/modules/ingest-common/joni-2.1.6.jar 216 | x elasticsearch-6.2.2/modules/ingest-common/ingest-common-6.2.2.jar 217 | x elasticsearch-6.2.2/modules/ingest-common/plugin-descriptor.properties 218 | x elasticsearch-6.2.2/modules/ingest-common/jcodings-1.0.12.jar 219 | x elasticsearch-6.2.2/modules/analysis-common/ 220 | x elasticsearch-6.2.2/modules/analysis-common/plugin-descriptor.properties 221 | x elasticsearch-6.2.2/modules/analysis-common/analysis-common-6.2.2.jar 222 | x elasticsearch-6.2.2/modules/parent-join/ 223 | x elasticsearch-6.2.2/modules/parent-join/plugin-descriptor.properties 224 | x elasticsearch-6.2.2/modules/parent-join/parent-join-6.2.2.jar 225 | x elasticsearch-6.2.2/modules/lang-mustache/ 226 | # For more information, consult the network module documentation. 227 | x elasticsearch-6.2.2/modules/lang-mustache/plugin-security.policy 228 | x elasticsearch-6.2.2/modules/lang-mustache/lang-mustache-6.2.2.jar 229 | x elasticsearch-6.2.2/modules/lang-mustache/plugin-descriptor.properties 230 | x elasticsearch-6.2.2/modules/lang-mustache/compiler-0.9.3.jar 231 | x elasticsearch-6.2.2/modules/mapper-extras/ 232 | x elasticsearch-6.2.2/modules/mapper-extras/plugin-descriptor.properties 233 | x elasticsearch-6.2.2/modules/mapper-extras/mapper-extras-6.2.2.jar 234 | x elasticsearch-6.2.2/modules/lang-expression/ 235 | x elasticsearch-6.2.2/modules/lang-expression/asm-5.0.4.jar 236 | x elasticsearch-6.2.2/modules/lang-expression/lucene-expressions-7.2.1.jar 237 | x elasticsearch-6.2.2/modules/lang-expression/plugin-security.policy 238 | x elasticsearch-6.2.2/modules/lang-expression/asm-commons-5.0.4.jar 239 | x elasticsearch-6.2.2/modules/lang-expression/asm-tree-5.0.4.jar 240 | x elasticsearch-6.2.2/modules/lang-expression/antlr4-runtime-4.5.1-1.jar 241 | x elasticsearch-6.2.2/modules/lang-expression/plugin-descriptor.properties 242 | x elasticsearch-6.2.2/modules/lang-expression/lang-expression-6.2.2.jar 243 | x elasticsearch-6.2.2/plugins/ 244 | x elasticsearch-6.2.2/logs/ 245 | CorningSunMac:es_slave corning$ ls 246 | elasticsearch-6.2.2 elasticsearch-6.2.2.tar.gz 247 | CorningSunMac:es_slave corning$ cp -r elasticsearch-6.2.2 es_slave1 248 | CorningSunMac:es_slave corning$ cp -r elasticsearch-6.2.2 es_slave2 249 | CorningSunMac:es_slave corning$ ls 250 | elasticsearch-6.2.2 elasticsearch-6.2.2.tar.gz es_slave1 es_slave2 251 | CorningSunMac:es_slave corning$ vi es_slave1/config/elasticsearch.yml 252 | CorningSunMac:es_slave corning$ cd es_slave1 253 | CorningSunMac:es_slave1 corning$ ./bin/elasticsearch 254 | Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. 255 | [2018-02-26T10:26:31,148][INFO ][o.e.n.Node ] [slave1] initializing ... 256 | [2018-02-26T10:26:31,232][INFO ][o.e.e.NodeEnvironment ] [slave1] using [1] data paths, mounts [[/ (/dev/disk1s1)]], net usable_space [109.5gb], net total_space [465.7gb], types [apfs] 257 | [2018-02-26T10:26:31,232][INFO ][o.e.e.NodeEnvironment ] [slave1] heap size [989.8mb], compressed ordinary object pointers [true] 258 | [2018-02-26T10:26:31,234][INFO ][o.e.n.Node ] [slave1] node name [slave1], node ID [qLXbdcA1TdOTTpJfqKVwtg] 259 | [2018-02-26T10:26:31,234][INFO ][o.e.n.Node ] [slave1] version[6.2.2], pid[11963], build[10b1edd/2018-02-16T19:01:30.685723Z], OS[Mac OS X/10.13.3/x86_64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/9/9+181] 260 | [2018-02-26T10:26:31,234][INFO ][o.e.n.Node ] [slave1] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/var/folders/mg/pxtj807539j2bbfwcmfprsw80000gn/T/elasticsearch.DgobdeDu, -XX:+HeapDumpOnOutOfMemoryError, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Djava.locale.providers=COMPAT, -Des.path.home=/Users/corning/local/elastic/es_slave/es_slave1, -Des.path.conf=/Users/corning/local/elastic/es_slave/es_slave1/config] 261 | [2018-02-26T10:26:31,697][INFO ][o.e.p.PluginsService ] [slave1] loaded module [aggs-matrix-stats] 262 | [2018-02-26T10:26:31,697][INFO ][o.e.p.PluginsService ] [slave1] loaded module [analysis-common] 263 | [2018-02-26T10:26:31,697][INFO ][o.e.p.PluginsService ] [slave1] loaded module [ingest-common] 264 | [2018-02-26T10:26:31,697][INFO ][o.e.p.PluginsService ] [slave1] loaded module [lang-expression] 265 | [2018-02-26T10:26:31,697][INFO ][o.e.p.PluginsService ] [slave1] loaded module [lang-mustache] 266 | [2018-02-26T10:26:31,697][INFO ][o.e.p.PluginsService ] [slave1] loaded module [lang-painless] 267 | [2018-02-26T10:26:31,697][INFO ][o.e.p.PluginsService ] [slave1] loaded module [mapper-extras] 268 | [2018-02-26T10:26:31,697][INFO ][o.e.p.PluginsService ] [slave1] loaded module [parent-join] 269 | [2018-02-26T10:26:31,698][INFO ][o.e.p.PluginsService ] [slave1] loaded module [percolator] 270 | [2018-02-26T10:26:31,698][INFO ][o.e.p.PluginsService ] [slave1] loaded module [rank-eval] 271 | [2018-02-26T10:26:31,698][INFO ][o.e.p.PluginsService ] [slave1] loaded module [reindex] 272 | [2018-02-26T10:26:31,698][INFO ][o.e.p.PluginsService ] [slave1] loaded module [repository-url] 273 | [2018-02-26T10:26:31,698][INFO ][o.e.p.PluginsService ] [slave1] loaded module [transport-netty4] 274 | [2018-02-26T10:26:31,698][INFO ][o.e.p.PluginsService ] [slave1] loaded module [tribe] 275 | [2018-02-26T10:26:31,699][INFO ][o.e.p.PluginsService ] [slave1] no plugins loaded 276 | [2018-02-26T10:26:33,473][INFO ][o.e.d.DiscoveryModule ] [slave1] using discovery type [zen] 277 | [2018-02-26T10:26:33,854][INFO ][o.e.n.Node ] [slave1] initialized 278 | [2018-02-26T10:26:33,854][INFO ][o.e.n.Node ] [slave1] starting ... 279 | [2018-02-26T10:26:33,976][INFO ][o.e.t.TransportService ] [slave1] publish_address {127.0.0.1:9301}, bound_addresses {127.0.0.1:9301} 280 | [2018-02-26T10:26:37,137][INFO ][o.e.c.s.ClusterApplierService] [slave1] detected_master {master}{mF4GZ8u0T8eKC8iHNzTt_w}{x7mBUXVhRbiQ1GTgz8t3qw}{127.0.0.1}{127.0.0.1:9300}, added {{master}{mF4GZ8u0T8eKC8iHNzTt_w}{x7mBUXVhRbiQ1GTgz8t3qw}{127.0.0.1}{127.0.0.1:9300},}, reason: apply cluster state (from master [master {master}{mF4GZ8u0T8eKC8iHNzTt_w}{x7mBUXVhRbiQ1GTgz8t3qw}{127.0.0.1}{127.0.0.1:9300} committed version [3]]) 281 | [2018-02-26T10:26:37,218][INFO ][o.e.h.n.Netty4HttpServerTransport] [slave1] publish_address {127.0.0.1:9201}, bound_addresses {127.0.0.1:9201} 282 | [2018-02-26T10:26:37,219][INFO ][o.e.n.Node ] [slave1] started 283 | [2018-02-26T10:27:04,106][INFO ][o.e.c.s.ClusterApplierService] [slave1] added {{slave2}{LFTX2kxBS9K4eB2AgSUaNg}{-HRWBruwTiCVYd0O0xTU7w}{127.0.0.1}{127.0.0.1:9302},}, reason: apply cluster state (from master [master {master}{mF4GZ8u0T8eKC8iHNzTt_w}{x7mBUXVhRbiQ1GTgz8t3qw}{127.0.0.1}{127.0.0.1:9300} committed version [4]]) 284 | ``` -------------------------------------------------------------------------------- /doc/3-1_基础概念.md: -------------------------------------------------------------------------------- 1 | # 3-1 基础概念 2 | 3 | * 集群和节点 4 | 5 | ![](./img/集群和节点.png) 6 | 7 | * 索引:含有相同属性的文档集合 8 | * 类型:索引可以定义一个或多个类型,文档必须属于一个类型 9 | * 文档:文档是可以被索引的基本数据单位 10 | 11 | * 分片:每个索引都有多个分片,每个分片是一个Lucene索引 12 | * 备份:拷贝一份分片就完成了分片的备份 13 | 14 | -------------------------------------------------------------------------------- /doc/4-1_索引创建.md: -------------------------------------------------------------------------------- 1 | # 4-1 索引创建 2 | 3 | ## RESTFul API 4 | 5 | * API基本格式 6 | http://:/<索引>/<类型>/<文档id> 7 | 8 | * 常用HTTP动词 9 | GET/PUT/POST/DELETE 10 | 11 | ## 创建索引 12 | 13 | * 非结构化创建 14 | 15 | * 结构化创建 16 | 17 | ## 创建结构化索引 18 | 19 | ### POST http://localhost:9200/book/novel/_mappings 20 | 21 | * 请求 22 | ```json 23 | { 24 | "novel": { 25 | "properties": { 26 | "title": { 27 | "type": "text" 28 | } 29 | } 30 | } 31 | } 32 | ``` 33 | * 返回 34 | ```json 35 | { 36 | "acknowledged": true 37 | } 38 | ``` 39 | 40 | ## 懒得敲代码的,可以直接点击下面按钮~~ 41 | 42 | [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/ddfd5917ee60af2cc714) 43 | 44 | ![](./img/elasticsearch-postman.png) 45 | 46 | 47 | ### PUT http://127.0.0.1:9200/people 48 | 49 | * 请求 50 | 51 | ```json 52 | { 53 | "mappings": { 54 | "man": { 55 | "properties": { 56 | "id": { 57 | "type": "long" 58 | }, 59 | "name": { 60 | "type": "text" 61 | }, 62 | "gender": { 63 | "type": "boolean" 64 | }, 65 | "country":{ 66 | "type": "text" 67 | }, 68 | "age": { 69 | "type": "integer" 70 | }, 71 | "date": { 72 | "type": "date", 73 | "format": "date_hour_minute_second_millis||date" 74 | } 75 | } 76 | } 77 | } 78 | } 79 | ``` 80 | 81 | * 返回 82 | 83 | ```json 84 | { 85 | "acknowledged": true, 86 | "shards_acknowledged": true, 87 | "index": "people" 88 | } 89 | ``` 90 | 91 | ## 检查结果 92 | 93 | ![](./img/elasticsearch-head_index.png) -------------------------------------------------------------------------------- /doc/4-2_插入.md: -------------------------------------------------------------------------------- 1 | # 4-2 插入 2 | 3 | ## 指定文档id插入 4 | 5 | PUT http://127.0.0.1:9200/people/man/1 6 | 7 | * 请求 8 | 9 | ```json 10 | { 11 | "name":"瓦力", 12 | "country":"China", 13 | "age": 30, 14 | "date": "1987-03-07" 15 | } 16 | ``` 17 | 18 | * 返回 19 | 20 | ```json 21 | { 22 | "_index": "people", 23 | "_type": "man", 24 | "_id": "1", 25 | "_version": 1, 26 | "result": "created", 27 | "_shards": { 28 | "total": 2, 29 | "successful": 2, 30 | "failed": 0 31 | }, 32 | "_seq_no": 0, 33 | "_primary_term": 1 34 | } 35 | ``` 36 | 37 | ## 自动产生文档id插入 38 | 39 | POST http://127.0.0.1:9200/people/man 40 | 41 | * 请求 42 | 43 | ```json 44 | { 45 | "name":"超重瓦力", 46 | "country":"China", 47 | "age": 30, 48 | "date": "1987-03-07" 49 | } 50 | ``` 51 | 52 | * 返回 53 | 54 | ```json 55 | { 56 | "_index": "people", 57 | "_type": "man", 58 | "_id": "p0Ay0GEBldyi9655FMCT", 59 | "_version": 1, 60 | "result": "created", 61 | "_shards": { 62 | "total": 2, 63 | "successful": 2, 64 | "failed": 0 65 | }, 66 | "_seq_no": 0, 67 | "_primary_term": 1 68 | } 69 | ``` 70 | 71 | ## 数据插入结果 72 | 73 | ![](./img/es_data_people.png) -------------------------------------------------------------------------------- /doc/4-3_修改.md: -------------------------------------------------------------------------------- 1 | # 4-3 修改 2 | 3 | 4 | ## 直接修改 5 | 6 | POST http://127.0.0.1:9200/people/man/1/_update 7 | 8 | * 请求 9 | 10 | ```json 11 | { 12 | "doc": { 13 | "name":"谁是瓦力" 14 | } 15 | } 16 | ``` 17 | 18 | * 返回 19 | 20 | ```json 21 | { 22 | "_index": "people", 23 | "_type": "man", 24 | "_id": "1", 25 | "_version": 2, 26 | "result": "updated", 27 | "_shards": { 28 | "total": 2, 29 | "successful": 2, 30 | "failed": 0 31 | }, 32 | "_seq_no": 1, 33 | "_primary_term": 1 34 | } 35 | ``` 36 | 37 | ## 脚本修改1 38 | 39 | POST http://127.0.0.1:9200/people/man/1/_update 40 | 41 | * 请求 42 | 43 | ```json 44 | { 45 | "script": { 46 | "lang": "painless", 47 | "inline": "ctx._source.age += 10" 48 | } 49 | } 50 | ``` 51 | 52 | * 返回 53 | 54 | ```json 55 | { 56 | "_index": "people", 57 | "_type": "man", 58 | "_id": "1", 59 | "_version": 3, 60 | "result": "updated", 61 | "_shards": { 62 | "total": 2, 63 | "successful": 2, 64 | "failed": 0 65 | }, 66 | "_seq_no": 2, 67 | "_primary_term": 1 68 | } 69 | ``` 70 | 71 | ## 脚本修改2 72 | 73 | POST http://127.0.0.1:9200/people/man/1/_update 74 | 75 | * 请求 76 | 77 | ```json 78 | { 79 | "script": { 80 | "lang": "painless", 81 | "inline": "ctx._source.age = params.age", 82 | "params": { 83 | "age": 100 84 | } 85 | } 86 | } 87 | ``` 88 | 89 | * 返回 90 | 91 | ```json 92 | { 93 | "_index": "people", 94 | "_type": "man", 95 | "_id": "1", 96 | "_version": 4, 97 | "result": "updated", 98 | "_shards": { 99 | "total": 2, 100 | "successful": 2, 101 | "failed": 0 102 | }, 103 | "_seq_no": 3, 104 | "_primary_term": 1 105 | } 106 | ``` 107 | 108 | ## 检查结果 109 | 110 | ![](./img/es_data_people_update.png) 111 | 112 | -------------------------------------------------------------------------------- /doc/4-4_删除.md: -------------------------------------------------------------------------------- 1 | # 4-4 删除 2 | 3 | ## 删除文档 4 | 5 | DELETE http://127.0.0.1:9200/people/man/1 6 | 7 | * 请求 8 | 9 | 无 10 | 11 | * 返回 12 | 13 | ```json 14 | { 15 | "_index": "people", 16 | "_type": "man", 17 | "_id": "1", 18 | "_version": 5, 19 | "result": "deleted", 20 | "_shards": { 21 | "total": 2, 22 | "successful": 2, 23 | "failed": 0 24 | }, 25 | "_seq_no": 4, 26 | "_primary_term": 1 27 | } 28 | ``` 29 | 30 | ## 删除索引 31 | 32 | DELETE http://127.0.0.1:9200/people 33 | 34 | * 请求 35 | 36 | 无 37 | 38 | * 返回 39 | 40 | ```json 41 | { 42 | "acknowledged": true 43 | } 44 | ``` 45 | 46 | > 还可以通过,head 插件在页面进行删除操作 47 | 48 | 49 | -------------------------------------------------------------------------------- /doc/4-5_查询.md: -------------------------------------------------------------------------------- 1 | # 4-5 查询 2 | 3 | * 简单查询 4 | * 条件查询 5 | * 聚合查询 6 | 7 | ## 初始化 book 8 | 9 | ### 创建索引 10 | 11 | PUT http://127.0.0.1:9200/book 12 | 13 | * 请求 14 | 15 | ```json 16 | { 17 | "mappings": { 18 | "novel": { 19 | "properties": { 20 | "word_count": { 21 | "type": "integer" 22 | }, 23 | "author": { 24 | "type": "keyword" 25 | }, 26 | "title": { 27 | "type": "text" 28 | }, 29 | "publish_date":{ 30 | "type": "date", 31 | "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis" 32 | } 33 | } 34 | } 35 | } 36 | } 37 | ``` 38 | 39 | * 返回 40 | 41 | ```json 42 | { 43 | "acknowledged": true, 44 | "shards_acknowledged": true, 45 | "index": "book" 46 | } 47 | ``` 48 | 49 | ### 初始化数据 50 | 51 | 使用 `bulk` 方式初始化数据,具体可以参考:http://queirozf.com/entries/elasticsearch-bulk-inserting-examples 52 | 53 | > 需要注意,json文本必须以新的一行结尾,否则会报错 54 | 55 | POST http://127.0.0.1:9200/book/novel/_bulk 56 | 57 | * 请求 58 | 59 | ```json 60 | { "index": {"_id": "1"} } 61 | { "author": "王五", "title": "菜谱", "word_count": 5000, "publish_date": "2002-10-01"} 62 | { "index": {"_id": "2"} } 63 | { "author": "瓦力", "title": "ElasticSearch入门", "word_count": 3000, "publish_date": "2007-08-20"} 64 | { "index": {"_id": "3"} } 65 | { "author": "很胖的瓦力", "title": "ElasticSearch精通", "word_count": 3000, "publish_date": "2017-10-01"} 66 | { "index": {"_id": "4"} } 67 | { "author": "牛魔王", "title": "芭蕉扇", "word_count": 1000, "publish_date": "2000-10-01"} 68 | { "index": {"_id": "5"} } 69 | { "author": "李三", "title": "Java入门", "word_count": 2000, "publish_date": "2002-11-01"} 70 | { "index": {"_id": "6"} } 71 | { "author": "李四", "title": "ElasticSearch大法好", "word_count": 1000, "publish_date": "2002-10-01"} 72 | { "index": {"_id": "7"} } 73 | { "author": "赵六", "title": "剑谱", "word_count": 10000, "publish_date": "2002-10-02"} 74 | { "index": {"_id": "8"} } 75 | { "author": "张三", "title": "移魂大法", "word_count": 1000, "publish_date": "2012-10-01"} 76 | { "index": {"_id": "9"} } 77 | { "author": "张三丰", "title": "太极拳", "word_count": 1000, "publish_date": "2002-10-01"} 78 | { "index": {"_id": "10"} } 79 | { "author": "张四", "title": "Python入门", "word_count": 2000, "publish_date": "2016-02-01"} 80 | { "index": {"_id": "11"} } 81 | { "author": "孙悟空", "title": "七十二变", "word_count": 1000, "publish_date": "2000-10-01"} 82 | 83 | ``` 84 | 85 | * 返回 86 | 87 | ```json 88 | { 89 | "took": 332, 90 | "errors": false, 91 | "items": [ 92 | { 93 | "index": { 94 | "_index": "book", 95 | "_type": "novel", 96 | "_id": "1", 97 | "_version": 1, 98 | "result": "created", 99 | "_shards": { 100 | "total": 2, 101 | "successful": 2, 102 | "failed": 0 103 | }, 104 | "_seq_no": 0, 105 | "_primary_term": 1, 106 | "status": 201 107 | } 108 | }, 109 | { 110 | "index": { 111 | "_index": "book", 112 | "_type": "novel", 113 | "_id": "2", 114 | "_version": 1, 115 | "result": "created", 116 | "_shards": { 117 | "total": 2, 118 | "successful": 2, 119 | "failed": 0 120 | }, 121 | "_seq_no": 0, 122 | "_primary_term": 1, 123 | "status": 201 124 | } 125 | }, 126 | { 127 | "index": { 128 | "_index": "book", 129 | "_type": "novel", 130 | "_id": "3", 131 | "_version": 1, 132 | "result": "created", 133 | "_shards": { 134 | "total": 2, 135 | "successful": 2, 136 | "failed": 0 137 | }, 138 | "_seq_no": 0, 139 | "_primary_term": 1, 140 | "status": 201 141 | } 142 | }, 143 | { 144 | "index": { 145 | "_index": "book", 146 | "_type": "novel", 147 | "_id": "4", 148 | "_version": 1, 149 | "result": "created", 150 | "_shards": { 151 | "total": 2, 152 | "successful": 2, 153 | "failed": 0 154 | }, 155 | "_seq_no": 1, 156 | "_primary_term": 1, 157 | "status": 201 158 | } 159 | }, 160 | { 161 | "index": { 162 | "_index": "book", 163 | "_type": "novel", 164 | "_id": "5", 165 | "_version": 1, 166 | "result": "created", 167 | "_shards": { 168 | "total": 2, 169 | "successful": 2, 170 | "failed": 0 171 | }, 172 | "_seq_no": 0, 173 | "_primary_term": 1, 174 | "status": 201 175 | } 176 | }, 177 | { 178 | "index": { 179 | "_index": "book", 180 | "_type": "novel", 181 | "_id": "6", 182 | "_version": 1, 183 | "result": "created", 184 | "_shards": { 185 | "total": 2, 186 | "successful": 2, 187 | "failed": 0 188 | }, 189 | "_seq_no": 2, 190 | "_primary_term": 1, 191 | "status": 201 192 | } 193 | }, 194 | { 195 | "index": { 196 | "_index": "book", 197 | "_type": "novel", 198 | "_id": "7", 199 | "_version": 1, 200 | "result": "created", 201 | "_shards": { 202 | "total": 2, 203 | "successful": 2, 204 | "failed": 0 205 | }, 206 | "_seq_no": 1, 207 | "_primary_term": 1, 208 | "status": 201 209 | } 210 | }, 211 | { 212 | "index": { 213 | "_index": "book", 214 | "_type": "novel", 215 | "_id": "8", 216 | "_version": 1, 217 | "result": "created", 218 | "_shards": { 219 | "total": 2, 220 | "successful": 2, 221 | "failed": 0 222 | }, 223 | "_seq_no": 1, 224 | "_primary_term": 1, 225 | "status": 201 226 | } 227 | }, 228 | { 229 | "index": { 230 | "_index": "book", 231 | "_type": "novel", 232 | "_id": "9", 233 | "_version": 1, 234 | "result": "created", 235 | "_shards": { 236 | "total": 2, 237 | "successful": 2, 238 | "failed": 0 239 | }, 240 | "_seq_no": 2, 241 | "_primary_term": 1, 242 | "status": 201 243 | } 244 | }, 245 | { 246 | "index": { 247 | "_index": "book", 248 | "_type": "novel", 249 | "_id": "10", 250 | "_version": 1, 251 | "result": "created", 252 | "_shards": { 253 | "total": 2, 254 | "successful": 2, 255 | "failed": 0 256 | }, 257 | "_seq_no": 3, 258 | "_primary_term": 1, 259 | "status": 201 260 | } 261 | }, 262 | { 263 | "index": { 264 | "_index": "book", 265 | "_type": "novel", 266 | "_id": "11", 267 | "_version": 1, 268 | "result": "created", 269 | "_shards": { 270 | "total": 2, 271 | "successful": 2, 272 | "failed": 0 273 | }, 274 | "_seq_no": 1, 275 | "_primary_term": 1, 276 | "status": 201 277 | } 278 | } 279 | ] 280 | } 281 | ``` 282 | 283 | ## 简单查询 284 | 285 | ### 根据id查询 286 | 287 | GET http://127.0.0.1:9200/book/novel/1 288 | 289 | * 请求 290 | 291 | 无 292 | 293 | * 返回 294 | 295 | ```json 296 | { 297 | "_index": "book", 298 | "_type": "novel", 299 | "_id": "1", 300 | "_version": 1, 301 | "found": true, 302 | "_source": { 303 | "author": "王五", 304 | "title": "菜谱", 305 | "word_count": 5000, 306 | "publish_date": "2002-10-01" 307 | } 308 | } 309 | ``` 310 | 311 | ## 条件查询 312 | 313 | ### 匹配所有 314 | 315 | POST http://127.0.0.1:9200/book/_search 316 | 317 | * 请求 318 | 319 | ```json 320 | { 321 | "query": { 322 | "match_all": {} 323 | } 324 | } 325 | ``` 326 | 327 | * 返回 328 | 329 | ```json 330 | { 331 | "took": 4, 332 | "timed_out": false, 333 | "_shards": { 334 | "total": 5, 335 | "successful": 5, 336 | "skipped": 0, 337 | "failed": 0 338 | }, 339 | "hits": { 340 | "total": 11, 341 | "max_score": 1, 342 | "hits": [ 343 | { 344 | "_index": "book", 345 | "_type": "novel", 346 | "_id": "5", 347 | "_score": 1, 348 | "_source": { 349 | "author": "李三", 350 | "title": "Java入门", 351 | "word_count": 2000, 352 | "publish_date": "2002-11-01" 353 | } 354 | }, 355 | { 356 | "_index": "book", 357 | "_type": "novel", 358 | "_id": "8", 359 | "_score": 1, 360 | "_source": { 361 | "author": "张三", 362 | "title": "移魂大法", 363 | "word_count": 1000, 364 | "publish_date": "2012-10-01" 365 | } 366 | }, 367 | { 368 | "_index": "book", 369 | "_type": "novel", 370 | "_id": "9", 371 | "_score": 1, 372 | "_source": { 373 | "author": "张三丰", 374 | "title": "太极拳", 375 | "word_count": 1000, 376 | "publish_date": "2002-10-01" 377 | } 378 | }, 379 | { 380 | "_index": "book", 381 | "_type": "novel", 382 | "_id": "10", 383 | "_score": 1, 384 | "_source": { 385 | "author": "张四", 386 | "title": "Python入门", 387 | "word_count": 2000, 388 | "publish_date": "2016-02-01" 389 | } 390 | }, 391 | { 392 | "_index": "book", 393 | "_type": "novel", 394 | "_id": "2", 395 | "_score": 1, 396 | "_source": { 397 | "author": "瓦力", 398 | "title": "ElasticSearch入门", 399 | "word_count": 3000, 400 | "publish_date": "2007-08-20" 401 | } 402 | }, 403 | { 404 | "_index": "book", 405 | "_type": "novel", 406 | "_id": "4", 407 | "_score": 1, 408 | "_source": { 409 | "author": "牛魔王", 410 | "title": "芭蕉扇", 411 | "word_count": 1000, 412 | "publish_date": "2000-10-01" 413 | } 414 | }, 415 | { 416 | "_index": "book", 417 | "_type": "novel", 418 | "_id": "6", 419 | "_score": 1, 420 | "_source": { 421 | "author": "李四", 422 | "title": "ElasticSearch大法好", 423 | "word_count": 1000, 424 | "publish_date": "2002-10-01" 425 | } 426 | }, 427 | { 428 | "_index": "book", 429 | "_type": "novel", 430 | "_id": "1", 431 | "_score": 1, 432 | "_source": { 433 | "author": "王五", 434 | "title": "菜谱", 435 | "word_count": 5000, 436 | "publish_date": "2002-10-01" 437 | } 438 | }, 439 | { 440 | "_index": "book", 441 | "_type": "novel", 442 | "_id": "7", 443 | "_score": 1, 444 | "_source": { 445 | "author": "赵六", 446 | "title": "剑谱", 447 | "word_count": 10000, 448 | "publish_date": "2002-10-02" 449 | } 450 | }, 451 | { 452 | "_index": "book", 453 | "_type": "novel", 454 | "_id": "3", 455 | "_score": 1, 456 | "_source": { 457 | "author": "很胖的瓦力", 458 | "title": "ElasticSearch精通", 459 | "word_count": 3000, 460 | "publish_date": "2017-10-01" 461 | } 462 | } 463 | ] 464 | } 465 | } 466 | ``` 467 | 468 | ### 查询分页 469 | 470 | POST http://127.0.0.1:9200/book/_search 471 | 472 | * 请求 473 | 474 | ```json 475 | { 476 | "query": { 477 | "match_all": {} 478 | }, 479 | "from": 1, 480 | "size": 1 481 | } 482 | ``` 483 | 484 | * 返回 485 | 486 | ```json 487 | { 488 | "took": 2, 489 | "timed_out": false, 490 | "_shards": { 491 | "total": 5, 492 | "successful": 5, 493 | "skipped": 0, 494 | "failed": 0 495 | }, 496 | "hits": { 497 | "total": 11, 498 | "max_score": 1, 499 | "hits": [ 500 | { 501 | "_index": "book", 502 | "_type": "novel", 503 | "_id": "8", 504 | "_score": 1, 505 | "_source": { 506 | "author": "张三", 507 | "title": "移魂大法", 508 | "word_count": 1000, 509 | "publish_date": "2012-10-01" 510 | } 511 | } 512 | ] 513 | } 514 | } 515 | ``` 516 | 517 | ### like 查询 518 | 519 | POST http://127.0.0.1:9200/book/_search 520 | 521 | 522 | * 请求 523 | 524 | ```json 525 | { 526 | "query": { 527 | "match": { 528 | "title": "ElasticSearch" 529 | } 530 | } 531 | } 532 | ``` 533 | 534 | * 返回 535 | 536 | ```json 537 | { 538 | "took": 2, 539 | "timed_out": false, 540 | "_shards": { 541 | "total": 5, 542 | "successful": 5, 543 | "skipped": 0, 544 | "failed": 0 545 | }, 546 | "hits": { 547 | "total": 3, 548 | "max_score": 0.73617005, 549 | "hits": [ 550 | { 551 | "_index": "book", 552 | "_type": "novel", 553 | "_id": "3", 554 | "_score": 0.73617005, 555 | "_source": { 556 | "author": "很胖的瓦力", 557 | "title": "ElasticSearch精通", 558 | "word_count": 3000, 559 | "publish_date": "2017-10-01" 560 | } 561 | }, 562 | { 563 | "_index": "book", 564 | "_type": "novel", 565 | "_id": "2", 566 | "_score": 0.49005118, 567 | "_source": { 568 | "author": "瓦力", 569 | "title": "ElasticSearch入门", 570 | "word_count": 3000, 571 | "publish_date": "2007-08-20" 572 | } 573 | }, 574 | { 575 | "_index": "book", 576 | "_type": "novel", 577 | "_id": "6", 578 | "_score": 0.43445712, 579 | "_source": { 580 | "author": "李四", 581 | "title": "ElasticSearch大法好", 582 | "word_count": 1000, 583 | "publish_date": "2002-10-01" 584 | } 585 | } 586 | ] 587 | } 588 | } 589 | ``` 590 | 591 | ### 查询排序 592 | 593 | POST http://127.0.0.1:9200/book/_search 594 | 595 | * 请求 596 | 597 | ```json 598 | { 599 | "query": { 600 | "match": { 601 | "title": "ElasticSearch" 602 | } 603 | }, 604 | "sort": [ 605 | {"publish_date": 606 | {"order": "desc"} 607 | } 608 | ] 609 | } 610 | ``` 611 | 612 | * 返回 613 | 614 | ```json 615 | { 616 | "took": 3, 617 | "timed_out": false, 618 | "_shards": { 619 | "total": 5, 620 | "successful": 5, 621 | "skipped": 0, 622 | "failed": 0 623 | }, 624 | "hits": { 625 | "total": 3, 626 | "max_score": null, 627 | "hits": [ 628 | { 629 | "_index": "book", 630 | "_type": "novel", 631 | "_id": "3", 632 | "_score": null, 633 | "_source": { 634 | "author": "很胖的瓦力", 635 | "title": "ElasticSearch精通", 636 | "word_count": 3000, 637 | "publish_date": "2017-10-01" 638 | }, 639 | "sort": [ 640 | 1506816000000 641 | ] 642 | }, 643 | { 644 | "_index": "book", 645 | "_type": "novel", 646 | "_id": "2", 647 | "_score": null, 648 | "_source": { 649 | "author": "瓦力", 650 | "title": "ElasticSearch入门", 651 | "word_count": 3000, 652 | "publish_date": "2007-08-20" 653 | }, 654 | "sort": [ 655 | 1187568000000 656 | ] 657 | }, 658 | { 659 | "_index": "book", 660 | "_type": "novel", 661 | "_id": "6", 662 | "_score": null, 663 | "_source": { 664 | "author": "李四", 665 | "title": "ElasticSearch大法好", 666 | "word_count": 1000, 667 | "publish_date": "2002-10-01" 668 | }, 669 | "sort": [ 670 | 1033430400000 671 | ] 672 | } 673 | ] 674 | } 675 | } 676 | ``` 677 | 678 | ## 聚合查询 679 | 680 | ### terms 681 | 682 | POST http://127.0.0.1:9200/book/_search 683 | 684 | * 请求 685 | 686 | ```json 687 | { 688 | "aggs": { 689 | "group_by_word_count": { 690 | "terms": { 691 | "field": "word_count" 692 | } 693 | } 694 | } 695 | } 696 | ``` 697 | 698 | * 返回 699 | 700 | ```json 701 | { 702 | "took": 12, 703 | "timed_out": false, 704 | "_shards": { 705 | "total": 5, 706 | "successful": 5, 707 | "skipped": 0, 708 | "failed": 0 709 | }, 710 | "hits": { 711 | "total": 11, 712 | "max_score": 1, 713 | "hits": [ 714 | { 715 | "_index": "book", 716 | "_type": "novel", 717 | "_id": "5", 718 | "_score": 1, 719 | "_source": { 720 | "author": "李三", 721 | "title": "Java入门", 722 | "word_count": 2000, 723 | "publish_date": "2002-11-01" 724 | } 725 | }, 726 | { 727 | "_index": "book", 728 | "_type": "novel", 729 | "_id": "8", 730 | "_score": 1, 731 | "_source": { 732 | "author": "张三", 733 | "title": "移魂大法", 734 | "word_count": 1000, 735 | "publish_date": "2012-10-01" 736 | } 737 | }, 738 | { 739 | "_index": "book", 740 | "_type": "novel", 741 | "_id": "9", 742 | "_score": 1, 743 | "_source": { 744 | "author": "张三丰", 745 | "title": "太极拳", 746 | "word_count": 1000, 747 | "publish_date": "2002-10-01" 748 | } 749 | }, 750 | { 751 | "_index": "book", 752 | "_type": "novel", 753 | "_id": "10", 754 | "_score": 1, 755 | "_source": { 756 | "author": "张四", 757 | "title": "Python入门", 758 | "word_count": 2000, 759 | "publish_date": "2016-02-01" 760 | } 761 | }, 762 | { 763 | "_index": "book", 764 | "_type": "novel", 765 | "_id": "2", 766 | "_score": 1, 767 | "_source": { 768 | "author": "瓦力", 769 | "title": "ElasticSearch入门", 770 | "word_count": 3000, 771 | "publish_date": "2007-08-20" 772 | } 773 | }, 774 | { 775 | "_index": "book", 776 | "_type": "novel", 777 | "_id": "4", 778 | "_score": 1, 779 | "_source": { 780 | "author": "牛魔王", 781 | "title": "芭蕉扇", 782 | "word_count": 1000, 783 | "publish_date": "2000-10-01" 784 | } 785 | }, 786 | { 787 | "_index": "book", 788 | "_type": "novel", 789 | "_id": "6", 790 | "_score": 1, 791 | "_source": { 792 | "author": "李四", 793 | "title": "ElasticSearch大法好", 794 | "word_count": 1000, 795 | "publish_date": "2002-10-01" 796 | } 797 | }, 798 | { 799 | "_index": "book", 800 | "_type": "novel", 801 | "_id": "1", 802 | "_score": 1, 803 | "_source": { 804 | "author": "王五", 805 | "title": "菜谱", 806 | "word_count": 5000, 807 | "publish_date": "2002-10-01" 808 | } 809 | }, 810 | { 811 | "_index": "book", 812 | "_type": "novel", 813 | "_id": "7", 814 | "_score": 1, 815 | "_source": { 816 | "author": "赵六", 817 | "title": "剑谱", 818 | "word_count": 10000, 819 | "publish_date": "2002-10-02" 820 | } 821 | }, 822 | { 823 | "_index": "book", 824 | "_type": "novel", 825 | "_id": "3", 826 | "_score": 1, 827 | "_source": { 828 | "author": "很胖的瓦力", 829 | "title": "ElasticSearch精通", 830 | "word_count": 3000, 831 | "publish_date": "2017-10-01" 832 | } 833 | } 834 | ] 835 | }, 836 | "aggregations": { 837 | "group_by_word_count": { 838 | "doc_count_error_upper_bound": 0, 839 | "sum_other_doc_count": 0, 840 | "buckets": [ 841 | { 842 | "key": 1000, 843 | "doc_count": 5 844 | }, 845 | { 846 | "key": 2000, 847 | "doc_count": 2 848 | }, 849 | { 850 | "key": 3000, 851 | "doc_count": 2 852 | }, 853 | { 854 | "key": 5000, 855 | "doc_count": 1 856 | }, 857 | { 858 | "key": 10000, 859 | "doc_count": 1 860 | } 861 | ] 862 | } 863 | } 864 | } 865 | ``` 866 | 867 | ### 多个 terms 868 | 869 | POST http://127.0.0.1:9200/book/_search 870 | 871 | * 请求 872 | 873 | ```json 874 | { 875 | "aggs": { 876 | "group_by_word_count": { 877 | "terms": { 878 | "field": "word_count" 879 | } 880 | }, 881 | "group_by_publish_date": { 882 | "terms": { 883 | "field": "publish_date" 884 | } 885 | } 886 | } 887 | } 888 | ``` 889 | 890 | * 返回 891 | 892 | ```json 893 | { 894 | "took": 4, 895 | "timed_out": false, 896 | "_shards": { 897 | "total": 5, 898 | "successful": 5, 899 | "skipped": 0, 900 | "failed": 0 901 | }, 902 | "hits": { 903 | "total": 11, 904 | "max_score": 1, 905 | "hits": [ 906 | { 907 | "_index": "book", 908 | "_type": "novel", 909 | "_id": "5", 910 | "_score": 1, 911 | "_source": { 912 | "author": "李三", 913 | "title": "Java入门", 914 | "word_count": 2000, 915 | "publish_date": "2002-11-01" 916 | } 917 | }, 918 | { 919 | "_index": "book", 920 | "_type": "novel", 921 | "_id": "8", 922 | "_score": 1, 923 | "_source": { 924 | "author": "张三", 925 | "title": "移魂大法", 926 | "word_count": 1000, 927 | "publish_date": "2012-10-01" 928 | } 929 | }, 930 | { 931 | "_index": "book", 932 | "_type": "novel", 933 | "_id": "9", 934 | "_score": 1, 935 | "_source": { 936 | "author": "张三丰", 937 | "title": "太极拳", 938 | "word_count": 1000, 939 | "publish_date": "2002-10-01" 940 | } 941 | }, 942 | { 943 | "_index": "book", 944 | "_type": "novel", 945 | "_id": "10", 946 | "_score": 1, 947 | "_source": { 948 | "author": "张四", 949 | "title": "Python入门", 950 | "word_count": 2000, 951 | "publish_date": "2016-02-01" 952 | } 953 | }, 954 | { 955 | "_index": "book", 956 | "_type": "novel", 957 | "_id": "2", 958 | "_score": 1, 959 | "_source": { 960 | "author": "瓦力", 961 | "title": "ElasticSearch入门", 962 | "word_count": 3000, 963 | "publish_date": "2007-08-20" 964 | } 965 | }, 966 | { 967 | "_index": "book", 968 | "_type": "novel", 969 | "_id": "4", 970 | "_score": 1, 971 | "_source": { 972 | "author": "牛魔王", 973 | "title": "芭蕉扇", 974 | "word_count": 1000, 975 | "publish_date": "2000-10-01" 976 | } 977 | }, 978 | { 979 | "_index": "book", 980 | "_type": "novel", 981 | "_id": "6", 982 | "_score": 1, 983 | "_source": { 984 | "author": "李四", 985 | "title": "ElasticSearch大法好", 986 | "word_count": 1000, 987 | "publish_date": "2002-10-01" 988 | } 989 | }, 990 | { 991 | "_index": "book", 992 | "_type": "novel", 993 | "_id": "1", 994 | "_score": 1, 995 | "_source": { 996 | "author": "王五", 997 | "title": "菜谱", 998 | "word_count": 5000, 999 | "publish_date": "2002-10-01" 1000 | } 1001 | }, 1002 | { 1003 | "_index": "book", 1004 | "_type": "novel", 1005 | "_id": "7", 1006 | "_score": 1, 1007 | "_source": { 1008 | "author": "赵六", 1009 | "title": "剑谱", 1010 | "word_count": 10000, 1011 | "publish_date": "2002-10-02" 1012 | } 1013 | }, 1014 | { 1015 | "_index": "book", 1016 | "_type": "novel", 1017 | "_id": "3", 1018 | "_score": 1, 1019 | "_source": { 1020 | "author": "很胖的瓦力", 1021 | "title": "ElasticSearch精通", 1022 | "word_count": 3000, 1023 | "publish_date": "2017-10-01" 1024 | } 1025 | } 1026 | ] 1027 | }, 1028 | "aggregations": { 1029 | "group_by_publish_date": { 1030 | "doc_count_error_upper_bound": 0, 1031 | "sum_other_doc_count": 0, 1032 | "buckets": [ 1033 | { 1034 | "key": 1033430400000, 1035 | "key_as_string": "2002-10-01 00:00:00", 1036 | "doc_count": 3 1037 | }, 1038 | { 1039 | "key": 970358400000, 1040 | "key_as_string": "2000-10-01 00:00:00", 1041 | "doc_count": 2 1042 | }, 1043 | { 1044 | "key": 1033516800000, 1045 | "key_as_string": "2002-10-02 00:00:00", 1046 | "doc_count": 1 1047 | }, 1048 | { 1049 | "key": 1036108800000, 1050 | "key_as_string": "2002-11-01 00:00:00", 1051 | "doc_count": 1 1052 | }, 1053 | { 1054 | "key": 1187568000000, 1055 | "key_as_string": "2007-08-20 00:00:00", 1056 | "doc_count": 1 1057 | }, 1058 | { 1059 | "key": 1349049600000, 1060 | "key_as_string": "2012-10-01 00:00:00", 1061 | "doc_count": 1 1062 | }, 1063 | { 1064 | "key": 1454284800000, 1065 | "key_as_string": "2016-02-01 00:00:00", 1066 | "doc_count": 1 1067 | }, 1068 | { 1069 | "key": 1506816000000, 1070 | "key_as_string": "2017-10-01 00:00:00", 1071 | "doc_count": 1 1072 | } 1073 | ] 1074 | }, 1075 | "group_by_word_count": { 1076 | "doc_count_error_upper_bound": 0, 1077 | "sum_other_doc_count": 0, 1078 | "buckets": [ 1079 | { 1080 | "key": 1000, 1081 | "doc_count": 5 1082 | }, 1083 | { 1084 | "key": 2000, 1085 | "doc_count": 2 1086 | }, 1087 | { 1088 | "key": 3000, 1089 | "doc_count": 2 1090 | }, 1091 | { 1092 | "key": 5000, 1093 | "doc_count": 1 1094 | }, 1095 | { 1096 | "key": 10000, 1097 | "doc_count": 1 1098 | } 1099 | ] 1100 | } 1101 | } 1102 | } 1103 | ``` 1104 | 1105 | ### stats 1106 | 1107 | POST http://127.0.0.1:9200/book/_search 1108 | 1109 | * 请求 1110 | 1111 | ```json 1112 | { 1113 | "aggs": { 1114 | "group_by_word_count": { 1115 | "stats": { 1116 | "field": "word_count" 1117 | } 1118 | } 1119 | } 1120 | } 1121 | ``` 1122 | 1123 | * 返回 1124 | 1125 | ```json 1126 | { 1127 | "took": 3, 1128 | "timed_out": false, 1129 | "_shards": { 1130 | "total": 5, 1131 | "successful": 5, 1132 | "skipped": 0, 1133 | "failed": 0 1134 | }, 1135 | "hits": { 1136 | "total": 11, 1137 | "max_score": 1, 1138 | "hits": [ 1139 | { 1140 | "_index": "book", 1141 | "_type": "novel", 1142 | "_id": "5", 1143 | "_score": 1, 1144 | "_source": { 1145 | "author": "李三", 1146 | "title": "Java入门", 1147 | "word_count": 2000, 1148 | "publish_date": "2002-11-01" 1149 | } 1150 | }, 1151 | { 1152 | "_index": "book", 1153 | "_type": "novel", 1154 | "_id": "8", 1155 | "_score": 1, 1156 | "_source": { 1157 | "author": "张三", 1158 | "title": "移魂大法", 1159 | "word_count": 1000, 1160 | "publish_date": "2012-10-01" 1161 | } 1162 | }, 1163 | { 1164 | "_index": "book", 1165 | "_type": "novel", 1166 | "_id": "9", 1167 | "_score": 1, 1168 | "_source": { 1169 | "author": "张三丰", 1170 | "title": "太极拳", 1171 | "word_count": 1000, 1172 | "publish_date": "2002-10-01" 1173 | } 1174 | }, 1175 | { 1176 | "_index": "book", 1177 | "_type": "novel", 1178 | "_id": "10", 1179 | "_score": 1, 1180 | "_source": { 1181 | "author": "张四", 1182 | "title": "Python入门", 1183 | "word_count": 2000, 1184 | "publish_date": "2016-02-01" 1185 | } 1186 | }, 1187 | { 1188 | "_index": "book", 1189 | "_type": "novel", 1190 | "_id": "2", 1191 | "_score": 1, 1192 | "_source": { 1193 | "author": "瓦力", 1194 | "title": "ElasticSearch入门", 1195 | "word_count": 3000, 1196 | "publish_date": "2007-08-20" 1197 | } 1198 | }, 1199 | { 1200 | "_index": "book", 1201 | "_type": "novel", 1202 | "_id": "4", 1203 | "_score": 1, 1204 | "_source": { 1205 | "author": "牛魔王", 1206 | "title": "芭蕉扇", 1207 | "word_count": 1000, 1208 | "publish_date": "2000-10-01" 1209 | } 1210 | }, 1211 | { 1212 | "_index": "book", 1213 | "_type": "novel", 1214 | "_id": "6", 1215 | "_score": 1, 1216 | "_source": { 1217 | "author": "李四", 1218 | "title": "ElasticSearch大法好", 1219 | "word_count": 1000, 1220 | "publish_date": "2002-10-01" 1221 | } 1222 | }, 1223 | { 1224 | "_index": "book", 1225 | "_type": "novel", 1226 | "_id": "1", 1227 | "_score": 1, 1228 | "_source": { 1229 | "author": "王五", 1230 | "title": "菜谱", 1231 | "word_count": 5000, 1232 | "publish_date": "2002-10-01" 1233 | } 1234 | }, 1235 | { 1236 | "_index": "book", 1237 | "_type": "novel", 1238 | "_id": "7", 1239 | "_score": 1, 1240 | "_source": { 1241 | "author": "赵六", 1242 | "title": "剑谱", 1243 | "word_count": 10000, 1244 | "publish_date": "2002-10-02" 1245 | } 1246 | }, 1247 | { 1248 | "_index": "book", 1249 | "_type": "novel", 1250 | "_id": "3", 1251 | "_score": 1, 1252 | "_source": { 1253 | "author": "很胖的瓦力", 1254 | "title": "ElasticSearch精通", 1255 | "word_count": 3000, 1256 | "publish_date": "2017-10-01" 1257 | } 1258 | } 1259 | ] 1260 | }, 1261 | "aggregations": { 1262 | "group_by_word_count": { 1263 | "count": 11, 1264 | "min": 1000, 1265 | "max": 10000, 1266 | "avg": 2727.2727272727275, 1267 | "sum": 30000 1268 | } 1269 | } 1270 | } 1271 | ``` 1272 | 1273 | -------------------------------------------------------------------------------- /doc/5-1_query.md: -------------------------------------------------------------------------------- 1 | # 5-1 query 2 | 3 | ## 高级查询 4 | 5 | * 子条件查询 6 | 7 | 特定字段查询所指特定值 8 | 9 | * 复合条件查询 10 | 11 | 以一定的逻辑组合子条件查询 12 | 13 | ## 子条件查询 14 | 15 | * Query context 16 | * Filter context 17 | 18 | ### Query context 19 | 20 | 在查询过程中,除了判断文档是否满足查询条件外,ES还会计算一个 `_score` 来标识匹配的程度,旨在判断目标文档和查询条件匹配的**有多好**。 21 | 22 | * 全文本查询 针对文本类型数据 23 | * 字段级别查询 针对结构化数据,如数字、日期等 24 | 25 | ## 查询示例 26 | 27 | POST http://127.0.0.1:9200/book/_search 28 | 29 | ### match 30 | 31 | title 匹配 "ElasticSearch" 或 "入门" 32 | 33 | ```json 34 | { 35 | "query": { 36 | "match": { 37 | "title": "ElasticSearch入门" 38 | } 39 | } 40 | } 41 | ``` 42 | 43 | ### match_phrase 44 | 45 | title 精确匹配 "ElasticSearch入门" 46 | 47 | ```json 48 | { 49 | "query": { 50 | "match_phrase": { 51 | "title": "ElasticSearch入门" 52 | } 53 | } 54 | } 55 | ``` 56 | 57 | ### multi_match 58 | 59 | author 或 title 匹配 "瓦力" 60 | 61 | ```json 62 | { 63 | "query": { 64 | "multi_match": { 65 | "query": "瓦力", 66 | "fields": ["author", "title"] 67 | } 68 | } 69 | } 70 | ``` 71 | 72 | ### query_string 73 | 74 | 所有字段匹配 "Python" 或 (匹配 "ElasticSearch" 和 "大法") 75 | 76 | ```json 77 | { 78 | "query": { 79 | "query_string": { 80 | "query": "(ElasticSearch AND 大法) OR Python" 81 | } 82 | } 83 | } 84 | ``` 85 | 86 | ### query_string.fields 87 | 88 | author 或 title 字段匹配 "瓦力" 或 "ElasticSearch" 89 | 90 | ```json 91 | { 92 | "query": { 93 | "query_string": { 94 | "query": "瓦力 OR ElasticSearch", 95 | "fields": ["author", "title"] 96 | } 97 | } 98 | } 99 | ``` 100 | 101 | ### term 102 | 103 | author 匹配 "瓦力" 104 | 105 | ```json 106 | { 107 | "query": { 108 | "term": { 109 | "author": "瓦力" 110 | } 111 | } 112 | } 113 | ``` 114 | 115 | ### range 116 | 117 | 1000 <= word_count <= 2000 118 | 119 | ```json 120 | { 121 | "query": { 122 | "range": { 123 | "word_count": { 124 | "gte": 1000, 125 | "lte": 2000 126 | } 127 | } 128 | } 129 | } 130 | ``` 131 | 132 | ### range 日期 133 | 134 | "2016-01-01" <= publish_date <= 现在 135 | 136 | ```json 137 | { 138 | "query": { 139 | "range": { 140 | "publish_date": { 141 | "gte": "2016-01-01", 142 | "lte": "now" 143 | } 144 | } 145 | } 146 | } 147 | ``` 148 | -------------------------------------------------------------------------------- /doc/5-2_filter.md: -------------------------------------------------------------------------------- 1 | # 5-2 filter 2 | 3 | ## Filter context 4 | 5 | 在查询过程中,只判断该文档是否**满足**条件,只有 Yes 或者 No。 6 | 7 | http://127.0.0.1:9200/book/_search 8 | 9 | * 请求 10 | 11 | ```json 12 | { 13 | "query": { 14 | "bool": { 15 | "filter": { 16 | "term": { 17 | "word_count": 1000 18 | } 19 | } 20 | } 21 | } 22 | } 23 | ``` 24 | 25 | * 返回 26 | 27 | ```json 28 | { 29 | "took": 15, 30 | "timed_out": false, 31 | "_shards": { 32 | "total": 5, 33 | "successful": 5, 34 | "skipped": 0, 35 | "failed": 0 36 | }, 37 | "hits": { 38 | "total": 5, 39 | "max_score": 0, 40 | "hits": [ 41 | { 42 | "_index": "book", 43 | "_type": "novel", 44 | "_id": "8", 45 | "_score": 0, 46 | "_source": { 47 | "author": "张三", 48 | "title": "移魂大法", 49 | "word_count": 1000, 50 | "publish_date": "2012-10-01" 51 | } 52 | }, 53 | { 54 | "_index": "book", 55 | "_type": "novel", 56 | "_id": "9", 57 | "_score": 0, 58 | "_source": { 59 | "author": "张三丰", 60 | "title": "太极拳", 61 | "word_count": 1000, 62 | "publish_date": "2002-10-01" 63 | } 64 | }, 65 | { 66 | "_index": "book", 67 | "_type": "novel", 68 | "_id": "4", 69 | "_score": 0, 70 | "_source": { 71 | "author": "牛魔王", 72 | "title": "芭蕉扇", 73 | "word_count": 1000, 74 | "publish_date": "2000-10-01" 75 | } 76 | }, 77 | { 78 | "_index": "book", 79 | "_type": "novel", 80 | "_id": "6", 81 | "_score": 0, 82 | "_source": { 83 | "author": "李四", 84 | "title": "ElasticSearch大法好", 85 | "word_count": 1000, 86 | "publish_date": "2002-10-01" 87 | } 88 | }, 89 | { 90 | "_index": "book", 91 | "_type": "novel", 92 | "_id": "11", 93 | "_score": 0, 94 | "_source": { 95 | "author": "孙悟空", 96 | "title": "七十二变", 97 | "word_count": 1000, 98 | "publish_date": "2000-10-01" 99 | } 100 | } 101 | ] 102 | } 103 | } 104 | ``` -------------------------------------------------------------------------------- /doc/5-3_复合查询.md: -------------------------------------------------------------------------------- 1 | # 5-3 复合查询 2 | 3 | ## 常用查询 4 | 5 | * 固定分数查询 6 | * 布尔查询 7 | 8 | 9 | ## 懒得敲代码的,可以直接点击下面按钮~~ 10 | 11 | [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/ddfd5917ee60af2cc714) 12 | 13 | ![](./img/elasticsearch-postman.png) 14 | 15 | -------------------------------------------------------------------------------- /doc/6-1_SpringBoot集成ElasticSearch.md: -------------------------------------------------------------------------------- 1 | # 6-1 SpringBoot集成ElasticSearch 2 | 3 | * SpringBoot 集成 ES 4 | * 图书信息管理接口开发 5 | 6 | ## 问题整理 7 | 8 | * `ClassNotFoundException: org.elasticsearch.plugins.xxx` 9 | 10 | 可以参考:https://github.com/elastic/elasticsearch/issues/21172 11 | 12 | -------------------------------------------------------------------------------- /doc/6-2_查询接口开发.md: -------------------------------------------------------------------------------- 1 | # 6-2 查询接口开发 2 | 3 | * 新增图书信息功能开发 4 | * 修改图书信息功能开发 5 | * 删除功能开发 6 | * 综合查询接口开发 7 | 8 | ## 代码 9 | 10 | ```java 11 | // 查询接口 12 | @GetMapping("/get/book/novel") 13 | public ResponseEntity get(@RequestParam(name = "id", defaultValue = "") String id) { 14 | GetResponse response = client.prepareGet(BOOK_INDEX, BOOK_TYPE_NOVEL, id).get(); 15 | if (!response.isExists()) { 16 | return new ResponseEntity(HttpStatus.NOT_FOUND); 17 | } 18 | return new ResponseEntity(response.getSource(), HttpStatus.OK); 19 | } 20 | ``` 21 | 22 | ## 问题整理 23 | 24 | * org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available 25 | 26 | 可以参考:[解决JAVA访问Elasticsearch的问题](https://www.codelast.com/%E5%8E%9F%E5%88%9B-%E8%A7%A3%E5%86%B3java%E8%AE%BF%E9%97%AEelasticsearch%E7%9A%84%E9%97%AE%E9%A2%98%EF%BC%9Aorg-elasticsearch-client-transport-nonodeavailableexception-none-of-the-configured-nodes/) 27 | 28 | 主要有下面三点: 29 | 30 | 1. 集群名称设置 31 | 2. 集群IP和端口设置 32 | 3. java 客户端和 elasticsearch 版本是否匹配 33 | 34 | -------------------------------------------------------------------------------- /doc/6-3_增加接口开发.md: -------------------------------------------------------------------------------- 1 | # 6-3 增加接口开发 2 | 3 | ## 代码 4 | 5 | ```java 6 | // 增加接口 7 | @PostMapping("/add/book/novel") 8 | public ResponseEntity add( 9 | @RequestParam(name = "title") String title, 10 | @RequestParam(name = "author") String author, 11 | @RequestParam(name = "word_count") int wordCount, 12 | @RequestParam(name = "publish_date") 13 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date publishDate) { 14 | 15 | try { 16 | XContentBuilder content = XContentFactory.jsonBuilder().startObject() 17 | .field("title", title) 18 | .field("author", author) 19 | .field("word_count", wordCount) 20 | .field("publish_date", publishDate.getTime()) 21 | .endObject(); 22 | 23 | IndexResponse response = client.prepareIndex(BOOK_INDEX, BOOK_TYPE_NOVEL) 24 | .setSource(content) 25 | .get(); 26 | 27 | return new ResponseEntity(response.getId(), HttpStatus.OK); 28 | } catch (IOException e) { 29 | logger.error(e.getMessage(), e); 30 | return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); 31 | } 32 | 33 | } 34 | ``` -------------------------------------------------------------------------------- /doc/6-4_删除接口开发.md: -------------------------------------------------------------------------------- 1 | # 6-4 删除接口开发 2 | 3 | ## 代码 4 | 5 | ```java 6 | // 删除接口 7 | @DeleteMapping("/delete/book/novel") 8 | @ResponseBody 9 | public ResponseEntity delete(@RequestParam(name = "id") String id) { 10 | DeleteResponse response = client.prepareDelete(BOOK_INDEX, BOOK_TYPE_NOVEL, id).get(); 11 | return new ResponseEntity(response.getResult().toString(), HttpStatus.OK); 12 | } 13 | ``` -------------------------------------------------------------------------------- /doc/6-5_更新接口开发.md: -------------------------------------------------------------------------------- 1 | # 6-5 更新接口开发 2 | 3 | ## 代码 4 | 5 | ```java 6 | // 更新接口 7 | @PutMapping("/update/book/novel") 8 | @ResponseBody 9 | public ResponseEntity update( 10 | @RequestParam(name = "id") String id, 11 | @RequestParam(name = "title", required = false) String title, 12 | @RequestParam(name = "author", required = false) String author, 13 | @RequestParam(name = "word_count", required = false) Integer wordCount, 14 | @RequestParam(name = "publish_date", required = false) 15 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date publishDate) { 16 | 17 | try { 18 | XContentBuilder builder = XContentFactory.jsonBuilder().startObject(); 19 | 20 | if (title != null) { 21 | builder.field("title", title); 22 | } 23 | if (author != null) { 24 | builder.field("author", author); 25 | } 26 | if (wordCount != null) { 27 | builder.field("word_count", wordCount); 28 | } 29 | if (publishDate != null) { 30 | builder.field("publish_date", publishDate.getTime()); 31 | } 32 | builder.endObject(); 33 | 34 | UpdateRequest update = new UpdateRequest(BOOK_INDEX, BOOK_TYPE_NOVEL, id); 35 | update.doc(builder); 36 | UpdateResponse response = client.update(update).get(); 37 | return new ResponseEntity(response.getResult().toString(), HttpStatus.OK); 38 | } catch (Exception e) { 39 | logger.error(e.getMessage(), e); 40 | return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); 41 | } 42 | 43 | } 44 | ``` 45 | 46 | ## 问题整理 47 | 48 | * Optional int parameter 'word_count' is present but cannot be translated into a null value due to being declared as a primitive type. 49 | 50 | 可以参考:https://stackoverflow.com/questions/23977629/optional-long-parameter-is-present-but-cannot-be-translated-into-a-null-value 51 | 52 | 主要原因是,int 类型作为参数时,不能为空,要设置为 Integer。 53 | 54 | -------------------------------------------------------------------------------- /doc/6-6_复合查询接口开发.md: -------------------------------------------------------------------------------- 1 | # 6-6 复合查询接口开发 2 | 3 | ## 代码 4 | 5 | ```java 6 | // 复合查询 7 | @PostMapping("query/book/novel") 8 | @ResponseBody 9 | public ResponseEntity query( 10 | @RequestParam(name = "author", required = false) String author, 11 | @RequestParam(name = "title", required = false) String title, 12 | @RequestParam(name = "gt_word_count", defaultValue = "0") int gtWordCount, 13 | @RequestParam(name = "lt_word_count", required = false) Integer ltWordCount) { 14 | 15 | BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); 16 | 17 | if (author != null) { 18 | boolQuery.must(QueryBuilders.matchQuery("author", author)); 19 | } 20 | 21 | if (title != null) { 22 | boolQuery.must(QueryBuilders.matchQuery("title", title)); 23 | } 24 | 25 | RangeQueryBuilder rangeQuery = QueryBuilders.rangeQuery("word_count").from(gtWordCount); 26 | if (ltWordCount != null && ltWordCount > 0) { 27 | rangeQuery.to(ltWordCount); 28 | } 29 | boolQuery.filter(rangeQuery); 30 | 31 | SearchRequestBuilder builder = client.prepareSearch(BOOK_INDEX).setTypes(BOOK_TYPE_NOVEL) 32 | .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 33 | .setQuery(boolQuery) 34 | .setFrom(0) 35 | .setSize(10); 36 | 37 | logger.debug(builder.toString()); 38 | 39 | SearchResponse response = builder.get(); 40 | 41 | List result = new ArrayList>(); 42 | for (SearchHit hit : response.getHits()) { 43 | result.add(hit.getSourceAsMap()); 44 | } 45 | 46 | return new ResponseEntity(result, HttpStatus.OK); 47 | 48 | } 49 | ``` -------------------------------------------------------------------------------- /doc/7-1_课程总结.md: -------------------------------------------------------------------------------- 1 | # 7-1 课程总结 2 | 3 | * ES 简介 4 | * 安装 5 | * 基础概念 6 | * 基本用法 7 | * 高级查询 8 | * 实战演练 9 | 10 | ## [瓦力老师](https://www.imooc.com/t/5646367)的后续课程 11 | 12 | ### [BAT大牛亲授 基于ElasticSearch的搜房网实战(收费)](https://coding.imooc.com/class/167.html#Anchor) 13 | 14 | -------------------------------------------------------------------------------- /doc/data/books.data: -------------------------------------------------------------------------------- 1 | { "index": {"_id": "1"} } 2 | { "author": "王五", "title": "菜谱", "word_count": 5000, "publish_date": "2002-10-01"} 3 | { "index": {"_id": "2"} } 4 | { "author": "瓦力", "title": "ElasticSearch入门", "word_count": 3000, "publish_date": "2007-08-20"} 5 | { "index": {"_id": "3"} } 6 | { "author": "很胖的瓦力", "title": "ElasticSearch精通", "word_count": 3000, "publish_date": "2017-10-01"} 7 | { "index": {"_id": "4"} } 8 | { "author": "牛魔王", "title": "芭蕉扇", "word_count": 1000, "publish_date": "2000-10-01"} 9 | { "index": {"_id": "5"} } 10 | { "author": "李三", "title": "Java入门", "word_count": 2000, "publish_date": "2002-11-01"} 11 | { "index": {"_id": "6"} } 12 | { "author": "李四", "title": "ElasticSearch大法好", "word_count": 1000, "publish_date": "2002-10-01"} 13 | { "index": {"_id": "7"} } 14 | { "author": "赵六", "title": "剑谱", "word_count": 10000, "publish_date": "2002-10-02"} 15 | { "index": {"_id": "8"} } 16 | { "author": "张三", "title": "移魂大法", "word_count": 1000, "publish_date": "2012-10-01"} 17 | { "index": {"_id": "9"} } 18 | { "author": "张三丰", "title": "太极拳", "word_count": 1000, "publish_date": "2002-10-01"} 19 | { "index": {"_id": "10"} } 20 | { "author": "张四", "title": "Python入门", "word_count": 2000, "publish_date": "2016-02-01"} 21 | { "index": {"_id": "11"} } 22 | { "author": "孙悟空", "title": "七十二变", "word_count": 1000, "publish_date": "2000-10-01"} 23 | -------------------------------------------------------------------------------- /doc/img/elasticsearch-head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imooc-java/ElasticSearch/1e44548f29bedb5f8aed7df2693e1e18039a3cf1/doc/img/elasticsearch-head.png -------------------------------------------------------------------------------- /doc/img/elasticsearch-head_cluster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imooc-java/ElasticSearch/1e44548f29bedb5f8aed7df2693e1e18039a3cf1/doc/img/elasticsearch-head_cluster.png -------------------------------------------------------------------------------- /doc/img/elasticsearch-head_index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imooc-java/ElasticSearch/1e44548f29bedb5f8aed7df2693e1e18039a3cf1/doc/img/elasticsearch-head_index.png -------------------------------------------------------------------------------- /doc/img/elasticsearch-postman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imooc-java/ElasticSearch/1e44548f29bedb5f8aed7df2693e1e18039a3cf1/doc/img/elasticsearch-postman.png -------------------------------------------------------------------------------- /doc/img/es_data_people.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imooc-java/ElasticSearch/1e44548f29bedb5f8aed7df2693e1e18039a3cf1/doc/img/es_data_people.png -------------------------------------------------------------------------------- /doc/img/es_data_people_update.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imooc-java/ElasticSearch/1e44548f29bedb5f8aed7df2693e1e18039a3cf1/doc/img/es_data_people_update.png -------------------------------------------------------------------------------- /doc/img/瓦力老师.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imooc-java/ElasticSearch/1e44548f29bedb5f8aed7df2693e1e18039a3cf1/doc/img/瓦力老师.jpg -------------------------------------------------------------------------------- /doc/img/获取Elastic下载地址.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imooc-java/ElasticSearch/1e44548f29bedb5f8aed7df2693e1e18039a3cf1/doc/img/获取Elastic下载地址.png -------------------------------------------------------------------------------- /doc/img/集群和节点.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imooc-java/ElasticSearch/1e44548f29bedb5f8aed7df2693e1e18039a3cf1/doc/img/集群和节点.png -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.imooc 8 | ElasticSearch 9 | war 10 | 1.0-SNAPSHOT 11 | 12 | 13 | 14 | 15 | CorningSun 16 | corningsun@163.com 17 | http://www.corningsun.com 18 | 19 | 20 | 21 | 22 | 23 | UTF-8 24 | LATEST 25 | 6.2.2 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-parent 31 | 1.5.6.RELEASE 32 | 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-web 38 | 39 | 40 | 41 | org.elasticsearch.client 42 | transport 43 | ${elasticsearch.version} 44 | 45 | 46 | 47 | 48 | org.apache.logging.log4j 49 | log4j-core 50 | 2.7 51 | 52 | 53 | org.projectlombok 54 | lombok 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | org.springframework.boot 63 | spring-boot-maven-plugin 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /src/main/java/com/imooc/elasticsearch/Application.java: -------------------------------------------------------------------------------- 1 | package com.imooc.elasticsearch; 2 | 3 | import org.apache.lucene.queryparser.flexible.core.builders.QueryBuilder; 4 | import org.elasticsearch.action.delete.DeleteResponse; 5 | import org.elasticsearch.action.get.GetResponse; 6 | import org.elasticsearch.action.index.IndexResponse; 7 | import org.elasticsearch.action.search.SearchRequestBuilder; 8 | import org.elasticsearch.action.search.SearchResponse; 9 | import org.elasticsearch.action.search.SearchType; 10 | import org.elasticsearch.action.update.UpdateRequest; 11 | import org.elasticsearch.action.update.UpdateResponse; 12 | import org.elasticsearch.client.transport.TransportClient; 13 | import org.elasticsearch.common.xcontent.XContentBuilder; 14 | import org.elasticsearch.common.xcontent.XContentFactory; 15 | import org.elasticsearch.index.query.BoolQueryBuilder; 16 | import org.elasticsearch.index.query.QueryBuilders; 17 | import org.elasticsearch.index.query.RangeQueryBuilder; 18 | import org.elasticsearch.search.SearchHit; 19 | import org.elasticsearch.search.SearchHits; 20 | import org.slf4j.Logger; 21 | import org.slf4j.LoggerFactory; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.boot.SpringApplication; 24 | import org.springframework.boot.autoconfigure.SpringBootApplication; 25 | import org.springframework.format.annotation.DateTimeFormat; 26 | import org.springframework.http.HttpStatus; 27 | import org.springframework.http.ResponseEntity; 28 | import org.springframework.web.bind.annotation.*; 29 | 30 | import java.io.IOException; 31 | import java.util.ArrayList; 32 | import java.util.Date; 33 | import java.util.List; 34 | import java.util.Map; 35 | 36 | /** 37 | * Created by corning on 2018/3/5. 38 | */ 39 | 40 | @SpringBootApplication 41 | @RestController 42 | public class Application { 43 | 44 | public static final Logger logger = LoggerFactory.getLogger(Application.class); 45 | 46 | public static void main(String[] args) { 47 | SpringApplication.run(Application.class, args); 48 | } 49 | 50 | public static final String BOOK_INDEX = "book"; 51 | public static final String BOOK_TYPE_NOVEL = "novel"; 52 | 53 | @Autowired 54 | private TransportClient client; 55 | 56 | @GetMapping("/") 57 | public String index() { 58 | return "index"; 59 | } 60 | 61 | // 查询接口 62 | @GetMapping("/get/book/novel") 63 | public ResponseEntity get(@RequestParam(name = "id", defaultValue = "") String id) { 64 | GetResponse response = client.prepareGet(BOOK_INDEX, BOOK_TYPE_NOVEL, id).get(); 65 | if (!response.isExists()) { 66 | return new ResponseEntity(HttpStatus.NOT_FOUND); 67 | } 68 | return new ResponseEntity(response.getSource(), HttpStatus.OK); 69 | } 70 | 71 | // 增加接口 72 | @PostMapping("/add/book/novel") 73 | public ResponseEntity add( 74 | @RequestParam(name = "title") String title, 75 | @RequestParam(name = "author") String author, 76 | @RequestParam(name = "word_count") int wordCount, 77 | @RequestParam(name = "publish_date") 78 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date publishDate) { 79 | 80 | try { 81 | XContentBuilder content = XContentFactory.jsonBuilder().startObject() 82 | .field("title", title) 83 | .field("author", author) 84 | .field("word_count", wordCount) 85 | .field("publish_date", publishDate.getTime()) 86 | .endObject(); 87 | 88 | IndexResponse response = client.prepareIndex(BOOK_INDEX, BOOK_TYPE_NOVEL) 89 | .setSource(content) 90 | .get(); 91 | 92 | return new ResponseEntity(response.getId(), HttpStatus.OK); 93 | } catch (IOException e) { 94 | logger.error(e.getMessage(), e); 95 | return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); 96 | } 97 | 98 | } 99 | 100 | // 删除接口 101 | @DeleteMapping("/delete/book/novel") 102 | @ResponseBody 103 | public ResponseEntity delete(@RequestParam(name = "id") String id) { 104 | DeleteResponse response = client.prepareDelete(BOOK_INDEX, BOOK_TYPE_NOVEL, id).get(); 105 | return new ResponseEntity(response.getResult().toString(), HttpStatus.OK); 106 | } 107 | 108 | 109 | // 更新接口 110 | @PutMapping("/update/book/novel") 111 | @ResponseBody 112 | public ResponseEntity update( 113 | @RequestParam(name = "id") String id, 114 | @RequestParam(name = "title", required = false) String title, 115 | @RequestParam(name = "author", required = false) String author, 116 | @RequestParam(name = "word_count", required = false) Integer wordCount, 117 | @RequestParam(name = "publish_date", required = false) 118 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date publishDate) { 119 | 120 | try { 121 | XContentBuilder builder = XContentFactory.jsonBuilder().startObject(); 122 | 123 | if (title != null) { 124 | builder.field("title", title); 125 | } 126 | if (author != null) { 127 | builder.field("author", author); 128 | } 129 | if (wordCount != null) { 130 | builder.field("word_count", wordCount); 131 | } 132 | if (publishDate != null) { 133 | builder.field("publish_date", publishDate.getTime()); 134 | } 135 | builder.endObject(); 136 | 137 | UpdateRequest update = new UpdateRequest(BOOK_INDEX, BOOK_TYPE_NOVEL, id); 138 | update.doc(builder); 139 | UpdateResponse response = client.update(update).get(); 140 | return new ResponseEntity(response.getResult().toString(), HttpStatus.OK); 141 | } catch (Exception e) { 142 | logger.error(e.getMessage(), e); 143 | return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR); 144 | } 145 | 146 | } 147 | 148 | // 复合查询 149 | @PostMapping("query/book/novel") 150 | @ResponseBody 151 | public ResponseEntity query( 152 | @RequestParam(name = "author", required = false) String author, 153 | @RequestParam(name = "title", required = false) String title, 154 | @RequestParam(name = "gt_word_count", defaultValue = "0") int gtWordCount, 155 | @RequestParam(name = "lt_word_count", required = false) Integer ltWordCount) { 156 | 157 | BoolQueryBuilder boolQuery = QueryBuilders.boolQuery(); 158 | 159 | if (author != null) { 160 | boolQuery.must(QueryBuilders.matchQuery("author", author)); 161 | } 162 | 163 | if (title != null) { 164 | boolQuery.must(QueryBuilders.matchQuery("title", title)); 165 | } 166 | 167 | RangeQueryBuilder rangeQuery = QueryBuilders.rangeQuery("word_count").from(gtWordCount); 168 | if (ltWordCount != null && ltWordCount > 0) { 169 | rangeQuery.to(ltWordCount); 170 | } 171 | boolQuery.filter(rangeQuery); 172 | 173 | SearchRequestBuilder builder = client.prepareSearch(BOOK_INDEX).setTypes(BOOK_TYPE_NOVEL) 174 | .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) 175 | .setQuery(boolQuery) 176 | .setFrom(0) 177 | .setSize(10); 178 | 179 | logger.debug(builder.toString()); 180 | 181 | SearchResponse response = builder.get(); 182 | 183 | List result = new ArrayList>(); 184 | for (SearchHit hit : response.getHits()) { 185 | result.add(hit.getSourceAsMap()); 186 | } 187 | 188 | return new ResponseEntity(result, HttpStatus.OK); 189 | 190 | } 191 | 192 | } 193 | -------------------------------------------------------------------------------- /src/main/java/com/imooc/elasticsearch/MyConfig.java: -------------------------------------------------------------------------------- 1 | package com.imooc.elasticsearch; 2 | 3 | import org.elasticsearch.client.transport.TransportClient; 4 | import org.elasticsearch.common.settings.Settings; 5 | import org.elasticsearch.common.transport.TransportAddress; 6 | import org.elasticsearch.transport.client.PreBuiltTransportClient; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | import java.net.InetAddress; 11 | import java.net.UnknownHostException; 12 | 13 | /** 14 | * Created by corning on 2018/3/5. 15 | */ 16 | @Configuration 17 | public class MyConfig { 18 | 19 | @Bean 20 | public TransportClient client() throws UnknownHostException { 21 | 22 | Settings settings = Settings.builder().put("cluster.name", "corning").build(); 23 | 24 | PreBuiltTransportClient client = new PreBuiltTransportClient(settings); 25 | 26 | int[] local_ports = {9300, 9301, 9302}; 27 | for (int port : local_ports) { 28 | client.addTransportAddress(new TransportAddress( 29 | InetAddress.getByName("localhost"), port 30 | )); 31 | } 32 | 33 | return client; 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/resources/log4j2.properties: -------------------------------------------------------------------------------- 1 | appender.console.type = Console 2 | appender.console.name = Console 3 | appender.console.layout.type = PatternLayout 4 | appender.console.layout.pattern = [%t] %-5p $c -%m%n 5 | 6 | rootLogger.level = info 7 | rootLogger.appenderRef.console.ref = console --------------------------------------------------------------------------------