Elasticsearch安装部署

2023-12-20 06:31:50

Elasticsearch安装部署

1.下载elasticsearch安装包:Elasticsearch 2.4.6 | Elastic?

? ? ?

? 下载中文分词器:Release v1.10.6 · medcl/elasticsearch-analysis-ik · GitHub

? ? ?

2.安装elasticsearch

rpm -ivh elasticsearch-2.4.6.rpm

3.安装中文分词器插件

?? 首先在elasticsearch安装目录下的 /plugins/下创建目录ik,然后copy elasticsearch-analysis-ik-1.10.6.zip的解压内容到ik目录 ? ? ?? 下,如下图:

? ?

?4.测试

#启动服务
service elasticsearch start  
#测试是否安装成功
curl  -XGET 'localhost:9200'

? ? 结果如下,则安装成功

{
  "name" : "Wrecker",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "uwqbAklAQdSWWid84430Tg",
  "version" : {
    "number" : "2.4.6",
    "build_hash" : "5376dca9f70f3abef96a77f4bb22720ace3340fd",
    "build_timestamp" : "2017-07-18T12:17:44Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}

? ?? 测试中文分词

#创建index索引
curl -XPUT http://localhost:9200/index  
#定义文档的字段,主要是指定使用IK插件
curl -XPOST http://localhost:9200/index/test/_mapping -d'
{
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word"
            }
        }
}'

#添加测试数据 
curl -XPOST http://localhost:9200/index/test/1 -d'
{"content":"浪费精力零零九零克己复礼"}'

? 查询

#查询
curl -XPOST http://localhost:9200/index/test/_search?pretty  -d'
{
    "query" : { "match" : { "content" : "浪费" }},
}'

?查询结果如下则安装成功

??

{
  "took" : 13,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 0.35355338,
    "hits" : [ {
      "_index" : "index",
      "_type" : "test",
      "_id" : "1",
      "_score" : 0.35355338,
      "_source" : {
        "content" : "浪费精力零零九零克己复礼"
      }
    } ]
  }
}

? ?

文章来源:https://blog.csdn.net/qq_25280443/article/details/84142611
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。