Elasticsearch + Kibana 起步
Elasticsearch + Kibana 起步
StanleySun 发表于3个月前
Elasticsearch + Kibana 起步
  • 发表于 3个月前
  • 阅读 5
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 学生专属云服务套餐 10元起购>>>   

下载Elasticsearch 

下载地址 https://www.elastic.co/downloads

下载并解压到 /usr/local/elasticsearch

 

启动Elasticsearch

cd /usr/local/elasticsearch
bin/elasticsearch

 

下载Kibana 

下载地址 https://www.elastic.co/downloads

下载并解压到 /usr/local/kibana

 

启动Kibana

cd /usr/local/kibana
bin/kibana

 

访问Kibana

浏览器访问http://localhost:5601 , 可以看的界面,说明配置正确。

 

在elasticsearch里创建一个template

创建文件/usr/local/scrapy.course-index-template.json, 内容如下

{
  "mappings": {
    "_default_": {
      "_all": {
        "enabled": true,
        "norms": {
          "enabled": false
        }
      },
      "dynamic_templates": [
        {
          "strings_as_keywords": {
            "match_mapping_type": "string",
            "mapping": {
              "type": "keyword"
            }
          }
        },
        {
          "unindexed_longs": {
            "match_mapping_type": "long",
            "mapping": {
              "type": "long",
              "index": false
            }
          }
        },
        {
          "unindexed_doubles": {
            "match_mapping_type": "double",
            "mapping": {
              "type": "float",
              "index": false
            }
          }
        },
        {
          "template1": {
            "mapping": {
              "doc_values": true,
              "ignore_above": 1024,
              "index": "not_analyzed",
              "type": "{dynamic_type}"
            },
            "match": "*"
          }
        }
      ],
      "properties": {
        "title": {
          "type": "keyword"
        },
        "subtitle": {
          "type": "text",
          "index": "analyzed"
        },
        "url": {
          "type": "keyword"
        },
        "status": {
          "type": "keyword"
        },
        "price": {
          "type": "keyword"
        },
        "rating": {
          "type": "integer"
        },
        "ratingNum": {
          "type": "integer"
        },
        "c_tags": {
          "type": "text",
          "index": "analyzed"
        },
        "smallPicture": {
          "type": "keyword"
        },
        "middlePicture": {
          "type": "keyword"
        },
        "largePicture": {
          "type": "keyword"
        },
        "about": {
          "type": "text",
          "index": "analyzed"
        },
        "goals": {
          "type": "text",
          "index": "analyzed"
        },
        "studentNum": {
          "type": "integer"
        },
        "hitNum": {
          "type": "integer"
        },
        "created": {
          "type": "date"
        },
        "updated": {
          "type": "date"
        }
      }
    }
  },
  "settings": {
    "index.refresh_interval": "5s"
  },
  "template": "scrapy.course"
}

导入template到elasticsearch

cd /usr/local
curl -XPUT 'http://localhost:9200/_template/crapy.course?pretty' -d@scrapy.course-index-template.json

 

插入数据

进入kibana : http://localhost:5601, 选择Dev Tools

在右侧,输入以下内容并点击尖头执行

put scrapy.course/normal/1
{
  "title":"Think in Java"
}

 

查询数据

Dev Tools 右侧输入一下命了,并执行

get scrapy.course/normal/1

执行结果

{
  "_index": "scrapy.course",
  "_type": "normal",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "title": "Think in Java"
  }
}

说明索引创建成功。

共有 人打赏支持
粉丝 6
博文 18
码字总数 12976
×
StanleySun
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: