侧边栏壁纸
博主头像
春潮带雨晚来急博主等级

行动起来,活在当下

  • 累计撰写 32 篇文章
  • 累计创建 1 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

elasticSearch

Administrator
2023-12-26 / 0 评论 / 0 点赞 / 72 阅读 / 18547 字

> ElasticSearch 7.*

---

```

//启动单节点

bin/elasticsearch -E node.name=node0 -E cluster.name=geektime -E path.data=node0_data

//安装插件

bin/elasticsearch-plugin install analysis-icu

//查看插件

bin/elasticsearch-plugin list

//查看安装的插件

GET http://localhost:9200/_cat/plugins?v

//start multi-nodes Cluster

bin/elasticsearch -E node.name=node0 -E cluster.name=geektime -E path.data=node0_data

bin/elasticsearch -E node.name=node1 -E cluster.name=geektime -E path.data=node1_data

bin/elasticsearch -E node.name=node2 -E cluster.name=geektime -E path.data=node2_data

bin/elasticsearch -E node.name=node3 -E cluster.name=geektime -E path.data=node3_data

//查看集群

GET http://localhost:9200

//查看nodes

GET _cat/nodes

GET _cluster/health

//kibana查看插件:

bin/kibana-plugin list

//kibana设置中文:

i18n.locale: "en" ===>>> i18n.locale: "zh-CN"

//安装cerebro

https://github.com/lmenezes/cerebro

wget https://github.com/lmenezes/cerebro/releases/download/v0.8.3/cerebro-0.8.3.tgz

//在logstash中导入新的数据,eg:movies.csv

在 logstash/bin下新建文件logstash.conf [如下:]

启动logstash并制定配置文件导入数据:

./logstash -f logstash.conf

```

---

```

ctrl + / 可以跳转到官方的api向导中

get _cluster/health 查看健康详情

GET /_cat/nodes?v 查看节点详情

# If no filters are given, the default is to select all nodes

curl -X GET "localhost:9200/_nodes"

# Explicitly select all nodes

curl -X GET "localhost:9200/_nodes/_all"

# Select just the local node

curl -X GET "localhost:9200/_nodes/_local"

# Select the elected master node

curl -X GET "localhost:9200/_nodes/_master"

# Select nodes by name, which can include wildcards

curl -X GET "localhost:9200/_nodes/node_name_goes_here"

curl -X GET "localhost:9200/_nodes/node_name_goes_*"

# Select nodes by address, which can include wildcards

curl -X GET "localhost:9200/_nodes/10.0.0.3,10.0.0.4"

curl -X GET "localhost:9200/_nodes/10.0.0.*"

# Select nodes by role

curl -X GET "localhost:9200/_nodes/_all,master:false"

curl -X GET "localhost:9200/_nodes/data:true,ingest:true"

curl -X GET "localhost:9200/_nodes/coordinating_only:true"

# Select nodes by custom attribute (e.g. with something like node.attr.rack: 2 in the configuration file)

curl -X GET "localhost:9200/_nodes/rack:2"

curl -X GET "localhost:9200/_nodes/ra*:2"

curl -X GET "localhost:9200/_nodes/ra*:2*"

```

---

- logstash.conf

```

input {

file {

path => "/opt/elk/newData/movies.csv" // 此处是制定新数据csv的位置

start_position => "beginning"

sincedb_path => "/dev/null"

}

}

filter {

csv {

separator => ","

columns => ["id","content","genre"]

}

mutate {

split => { "genre" => "|" }

remove_field => ["path", "host","@timestamp","message"]

}

mutate {

split => ["content", "("]

add_field => { "title" => "%{[content][0]}"}

add_field => { "year" => "%{[content][1]}"}

}

# mutate {

# gsub => [

#

# "year", "\\)", ""

# ]

# }

mutate {

convert => {

"year" => "integer"

}

strip => ["title"]

remove_field => ["path", "host","@timestamp","message","content"]

}

}

output {

elasticsearch {

hosts => "http://localhost:9200" // 此处是需要链接并且写入的es的地址;

index => "movies"

document_id => "%{id}"

}

stdout {}

```

##### ES修改字段类型:

- 因为ES无法直接修改类型,也无法直接修改索引名称

- 所以ES里面,只有创建,删除,复制操作:

###### 1.拿到某索引原先的索引结构

```

GET http://192.192.192.75:26927/commodity/_mapping?pretty=true

{

"commodity": {

"mappings": {

"commodity": {

"properties": {

"baseCategoryLastId": {

"type": "long"

},

"baseCategoryRootId": {

"type": "long"

},

"baseCategoryRootIdSort": {

"type": "long"

},

"baseCategorySecondId": {

"type": "long"

},

"baseCategorySecondIdSort": {

"type": "long"

},

"baseSale": {

"type": "integer"

},

"businessNo": {

"type": "integer"

},

"channelCategoryIds": {

"type": "nested",

"properties": {

"id": {

"type": "long"

},

"name": {

"type": "text"

},

"sort": {

"type": "integer"

}

}

},

"channelCommodityName": {

"type": "keyword",

"fields": {

"channelCommodityName": {

"type": "text",

"analyzer": "ik_max_word",

"search_analyzer": "ik_smart"

}

}

},

"channelCommodityNo": {

"type": "keyword"

},

"commodityType": {

"type": "integer"

},

"esPackageList": {

"type": "nested",

"properties": {

"baseCommodityName": {

"type": "text"

},

"baseCommodityNo": {

"type": "keyword"

},

"introduction": {

"type": "text"

}

}

},

"id": {

"type": "keyword"

},

"introduction": {

"type": "keyword",

"fields": {

"introduction": {

"type": "text",

"analyzer": "ik_max_word",

"search_analyzer": "ik_smart"

}

}

}

}

}

}

}

}

```

###### 2.再创建一个新的索引

- 索引名称取一个新的名字

- 将上面的结构拿下来,删除有索引名称的第一行

- 接口后面跟新的索引名称

```

PUT http://192.192.192.75:26927/commodity233

{

"mappings": {

"commodity": {

"properties": {

"baseCategoryLastId": {

"type": "long"

},

"baseCategoryRootId": {

"type": "long"

},

"baseCategoryRootIdSort": {

"type": "long修改为integer"

},

"baseCategorySecondId": {

"type": "long修改为integer"

},

"baseCategorySecondIdSort": {

"type": "long修改为integer"

},

"baseSale": {

"type": "integer"

},

"businessNo": {

"type": "integer"

},

"channelCategoryIds": {

"type": "nested",

"properties": {

"id": {

"type": "long"

},

"name": {

"type": "text"

},

"sort": {

"type": "integer"

}

}

},

"channelCommodityName": {

"type": "keyword",

"fields": {

"channelCommodityName": {

"type": "text",

"analyzer": "ik_max_word",

"search_analyzer": "ik_smart"

}

}

},

"channelCommodityNo": {

"type": "keyword"

},

"commodityType": {

"type": "integer"

},

"esPackageList": {

"type": "nested",

"properties": {

"baseCommodityName": {

"type": "text"

},

"baseCommodityNo": {

"type": "keyword"

},

"introduction": {

"type": "text"

}

}

},

"id": {

"type": "keyword"

},

"introduction": {

"type": "keyword",

"fields": {

"introduction": {

"type": "text",

"analyzer": "ik_max_word",

"search_analyzer": "ik_smart"

}

}

}

}

}

}

}

```

###### 3.重建索引【复制数据】

- 将原来索引里面的数据,复制到新的索引上面来

```

http://192.192.192.75:26927/_reindex

{

"source": {

"index": "commodity"

},

"dest": {

"index": "commodity233"

}

}

```

###### 4. 干掉老索引

```

http://192.192.192.75:26927/commodity

```

###### 5.这样索引就又干净了.... 但是不能修改索引的名称;所以又得再操作一遍;新建一个叫做commodity的索引,把233里面的数据复制过去

###### 6.经过测试,在复制数据的那一步,可能会导致数据丢失,就是复制过去的数据不够原来索引里面的数据。所以还是在专业运维的手里去操作

0

评论区