Elasticsearch安装和基本命令

发布于:2023-01-16 ⋅ 阅读:(540) ⋅ 点赞:(0)

Elasticsearch安装

https://pan.baidu.com/s/12ue7z2ubeBHrVuu5aoZ9ug

ftos

解决跨域访问
在这里插入图片描述

http.cors.enabled: true
http.cors.allow-origin: "*"

head 插件

cnpm install

npm run start

kibana

汉化

在国际化配置里面配置

在这里插入图片描述

i18n.locale: "zh-CN"

添加 ik 分词器,解压至当前目录即可

\elasticsearch-7.6.1\plugins

自定义单词划分

elasticsearch-7.6.1\plugins\ik\config

在这里插入图片描述

查看ik分词器是否安装

elasticsearch-7.6.1\bin>elasticsearch-plugin list
ik

使用

最小切分 ik_smart

GET _analyze
{
  "analyzer": "ik_smart",
  "text": "中国共产党"
}

在这里插入图片描述

最细粒度切分 ik_max_word

将穷尽单词的划分

GET _analyze
{
  "analyzer": "ik_max_word",
  "text": "中国共产党"
}

在这里插入图片描述

索引的基本操作

创建索引

PUT / 索引 / 类型名 / 文档 id

注意 类型名推荐使用 _doc

PUT /test1/type1/1
{
  "name": "加菲猫",
  "age": 18
}

创建具有数据类型的索引

PUT /test2
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text"
      },
      "age": {
        "type": "long"
      },
      "birth": {
        "type": "date"
      }
    }
  }
}

查看索引信息

GET test1

查看 es 信息

GET _cat/health

GET _cat/indices?v

在这里插入图片描述
新建一个索引 test3

PUT /test3/_doc/1
{
  "name": "加菲猫",
  "age": 18,
  "birth": "2001-1-1"
}

修改属性信息
1、暴力修改,相同路径,再次 put
存在问题:如果 put 时,少一个属性值,就会覆盖
2、post 方式进行修改

POST /test3/_doc/1/_update
{
  "doc": {
    "name": "法外狂徒张三"
  }
}

删除索引

DELETE test1

配置和阅读

这个写的很好
https://www.cnblogs.com/coderxz/p/13268417.html#1elasticsearch%E7%AE%80%E4%BB%8B

elasticsearch.yml

# ======================== Elasticsearch Configuration es d的配置文件=========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ----------------------------------es 配置集群 Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------es节点配置 Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# -----------------------------------es配置路径 Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# -----------------------------------es 缓存配置 Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ----------------------------------es 网络配置 Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# ---------------------------------集群可见配置 Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ----------------------------------es网关配置 Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

# 解决跨域访问
http.cors.enabled: true
http.cors.allow-origin: "*"
本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到