Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

第 24 章 Elasticsearch

目錄

24.1. 安裝 Elasticsearch
24.1.1. RPM 安裝
24.1.2. YUM 安裝
24.1.3. 測試安裝是否正常
24.2. 文檔API
24.2.1. 快速上手
24.2.2. 寫入 PUT/POST
24.2.3. 獲取 GET
24.2.3.1. _source
24.2.4. 檢查記錄是否存在
24.2.5. 刪除 Delete
24.2.6. 參數
24.2.6.1. pretty 格式化 json
24.3. 搜索
24.3.1. 分頁
24.3.2. 字元串搜索
24.3.3. Query DSL
24.3.3.1. match
24.3.3.2. multi_match
24.3.3.3. sort
24.3.3.4. _source
24.4. Plugin 插件管理
24.4.1. 手工安裝插件
24.4.2. plugin 命令
24.4.3. 插件測試
24.5. 映射
24.5.1. 查看 _mapping
24.5.2. 刪除 _mapping
24.5.3. 創建 _mapping
24.5.4. 修改 _mapping
24.5.5. 數據類型
24.5.5.1. date
24.6. Alias management 別名管理
24.6.1. 查看索引別名
24.6.2. 創建索引別名
24.6.3. 修改別名
24.6.4. 刪除別名
24.7. Example
24.7.1. 新聞資訊應用案例
24.8. FAQ
24.8.1. Plugin [analysis-ik] is incompatible with Elasticsearch [2.3.5]. Was designed for version [2.3.4]
24.8.2. mapper_parsing_exception: failed to parse [ctime]

http://www.elasticsearch.org/

24.1. 安裝 Elasticsearch

24.1.1. RPM 安裝

yum localinstall https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.3.4/elasticsearch-2.3.4.rpm
			

24.1.2. YUM 安裝

			
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch

cat >> /etc/yum.repos.d/elasticsearch.repo <<EOF
[elasticsearch-2.x]
name=Elasticsearch repository for 2.x packages
baseurl=https://packages.elastic.co/elasticsearch/2.x/centos
gpgcheck=1
gpgkey=https://packages.elastic.co/GPG-KEY-elasticsearch
enabled=1
EOF

yum install elasticsearch

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
			
			

查看 RPM 包中所含檔案

[root@localhost ~]# rpm -ql elasticsearch-2.3.4-1.noarch 
/etc/elasticsearch
/etc/elasticsearch/elasticsearch.yml
/etc/elasticsearch/logging.yml
/etc/elasticsearch/scripts
/etc/init.d/elasticsearch
/etc/sysconfig/elasticsearch
/usr/lib/sysctl.d
/usr/lib/sysctl.d/elasticsearch.conf
/usr/lib/systemd/system/elasticsearch.service
/usr/lib/tmpfiles.d
/usr/lib/tmpfiles.d/elasticsearch.conf
/usr/share/elasticsearch/LICENSE.txt
/usr/share/elasticsearch/NOTICE.txt
/usr/share/elasticsearch/README.textile
/usr/share/elasticsearch/bin
/usr/share/elasticsearch/bin/elasticsearch
/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec
/usr/share/elasticsearch/bin/elasticsearch.in.sh
/usr/share/elasticsearch/bin/plugin
/usr/share/elasticsearch/lib
/usr/share/elasticsearch/lib/HdrHistogram-2.1.6.jar
/usr/share/elasticsearch/lib/apache-log4j-extras-1.2.17.jar
/usr/share/elasticsearch/lib/commons-cli-1.3.1.jar
/usr/share/elasticsearch/lib/compiler-0.8.13.jar
/usr/share/elasticsearch/lib/compress-lzf-1.0.2.jar
/usr/share/elasticsearch/lib/elasticsearch-2.3.4.jar
/usr/share/elasticsearch/lib/guava-18.0.jar
/usr/share/elasticsearch/lib/hppc-0.7.1.jar
/usr/share/elasticsearch/lib/jackson-core-2.6.6.jar
/usr/share/elasticsearch/lib/jackson-dataformat-cbor-2.6.6.jar
/usr/share/elasticsearch/lib/jackson-dataformat-smile-2.6.6.jar
/usr/share/elasticsearch/lib/jackson-dataformat-yaml-2.6.6.jar
/usr/share/elasticsearch/lib/jna-4.1.0.jar
/usr/share/elasticsearch/lib/joda-convert-1.2.jar
/usr/share/elasticsearch/lib/joda-time-2.9.4.jar
/usr/share/elasticsearch/lib/jsr166e-1.1.0.jar
/usr/share/elasticsearch/lib/jts-1.13.jar
/usr/share/elasticsearch/lib/log4j-1.2.17.jar
/usr/share/elasticsearch/lib/lucene-analyzers-common-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-backward-codecs-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-core-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-grouping-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-highlighter-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-join-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-memory-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-misc-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-queries-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-queryparser-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-sandbox-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-spatial-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-spatial3d-5.5.0.jar
/usr/share/elasticsearch/lib/lucene-suggest-5.5.0.jar
/usr/share/elasticsearch/lib/netty-3.10.5.Final.jar
/usr/share/elasticsearch/lib/securesm-1.0.jar
/usr/share/elasticsearch/lib/snakeyaml-1.15.jar
/usr/share/elasticsearch/lib/spatial4j-0.5.jar
/usr/share/elasticsearch/lib/t-digest-3.0.jar
/usr/share/elasticsearch/modules
/usr/share/elasticsearch/modules/lang-expression
/usr/share/elasticsearch/modules/lang-expression/antlr4-runtime-4.5.1-1.jar
/usr/share/elasticsearch/modules/lang-expression/asm-5.0.4.jar
/usr/share/elasticsearch/modules/lang-expression/asm-commons-5.0.4.jar
/usr/share/elasticsearch/modules/lang-expression/lang-expression-2.3.4.jar
/usr/share/elasticsearch/modules/lang-expression/lucene-expressions-5.5.0.jar
/usr/share/elasticsearch/modules/lang-expression/plugin-descriptor.properties
/usr/share/elasticsearch/modules/lang-expression/plugin-security.policy
/usr/share/elasticsearch/modules/lang-groovy
/usr/share/elasticsearch/modules/lang-groovy/groovy-2.4.6-indy.jar
/usr/share/elasticsearch/modules/lang-groovy/lang-groovy-2.3.4.jar
/usr/share/elasticsearch/modules/lang-groovy/plugin-descriptor.properties
/usr/share/elasticsearch/modules/lang-groovy/plugin-security.policy
/usr/share/elasticsearch/modules/reindex
/usr/share/elasticsearch/modules/reindex/plugin-descriptor.properties
/usr/share/elasticsearch/modules/reindex/reindex-2.3.4.jar
/usr/share/elasticsearch/plugins
/var/lib/elasticsearch
/var/log/elasticsearch
/var/run/elasticsearch
			

24.1.3. 測試安裝是否正常

啟動

/etc/init.d/elasticsearch start			
			

連結測試

[root@localhost ~]# curl -X GET http://localhost:9200/
{
  "name" : "Jack of Hearts",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.3.4",
    "build_hash" : "e455fd0c13dceca8dbbdbb1665d068ae55dabe3f",
    "build_timestamp" : "2016-06-30T11:24:31Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.0"
  },
  "tagline" : "You Know, for Search"
}