ElasticSearch7.3.2-Rest实战指南-Index APIs

2023-12-03 12:58

本文主要是介绍ElasticSearch7.3.2-Rest实战指南-Index APIs,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 一、介绍
  • 二、Index APIs
    • 2.1、index create
    • 2.2、index delete
    • 2.3、delete index aliases
    • 2.4、flush
    • 2.5、get-field-mapping
    • 2.6、get-index
    • 2.7、get-settings
    • 2.8、put-mapping
    • 2.9、more APIs

一、介绍

curl是利用URL语法在命令行方式下工作的开源文件传输工具,使用url可以简单实现常见的get/post请求。简单的认为是可以在命令行下面访问url的一个工具。在centos的默认库里面是有curl工具的,如果没有请yum安装即可。

curl

-X 指定http的请求方法有 HEAD GET POST PUT DELETE

-d 指定要传输的数据

-H 指定http请求头信息

二、Index APIs

2.1、index create

  • aliases

索引别名

  • mappings

字段映射

  • settings

索引配置(副本数量、分片数量)

索引库名称必须要全部小写,不能以下划线开头,也不能包含逗号

  • 示例

  • settings设置

# 形式一
curl -XPUT 'http://10.143.228.25:9200/student?pretty' -H "Content-Type: application/json" -d '{"settings":{"number_of_shards":3,"number_of_replicas":0}}'# 形式二
curl -XPUT 'http://10.143.228.25:9200/student?pretty' -H "Content-Type: application/json" -d '{"settings":{"index":{"number_of_shards":3,"number_of_replicas":2}}}'

json示例

{"settings" : {"index" : {"number_of_shards" : 3, "number_of_replicas" : 2 }}
}
{"settings" : {"number_of_shards" : 3,"number_of_replicas" : 2}
}

response示例:

{"acknowledged" : true,"shards_acknowledged" : true,"index" : "student"
}
  • mapping设置
curl -XPUT 'http://10.143.228.25:9200/student?pretty' -H "Content-Type: application/json" -d '{"settings":{"number_of_shards":3},"mappings":{"properties":{"field1":{"type":"text"}}}}'

json示例

{"settings" : {"number_of_shards" : 3},"mappings" : {"properties" : {"field1" : { "type" : "text" }}}
}

response示例:

{"acknowledged" : true,"shards_acknowledged" : true,"index" : "student"
}
  • aliases设置
curl -XPUT 'http://10.143.228.25:9200/student?pretty' -H "Content-Type: application/json" -d '{"aliases":{"alias_1":{},"alias_2":{"filter":{"term":{"user":"kimchy"}},"routing":"kimchy"}}}'

json示例

{"aliases" : {"alias_1" : {},"alias_2" : {"filter" : {"term" : {"user" : "kimchy" }},"routing" : "kimchy"}}
}

response示例:

{"acknowledged" : true,"shards_acknowledged" : true,"index" : "student"
}
  • 推荐形式

一次性创建索引,并配置settings、mapping、aliases。

curl -XPUT 'http://10.143.228.25:9200/student?pretty' -H "Content-Type: application/json" -d '{"settings":{"number_of_shards":3,"number_of_replicas":2},"mappings":{"properties":{"id":{"type":"long","index":true},"name":{"type":"text","index":true},"age":{"type":"integer"},"address":{"type":"text"},"birthday":{"type":"date","index":true}}},"aliases":{"alias_1":{}}}'

json示例

{"settings": {"number_of_shards" : 3,"number_of_replicas" : 2},"mappings": {"properties": {"id": {"type": "long","index": true},"name": {"type": "text","index": true},"age": {"type": "integer"},"address": {"type": "text"},"birthday": {"type": "date","index": true}}},"aliases": {"alias_1": {}}
}

response示例:

{                                                                                                                                                       "acknowledged" : true,                                                                                                                                "shards_acknowledged" : true,                                                                                                                         "index" : "student"                                                                                                                                   
} 
  • 扩展阅读

https://www.elastic.co/guide/en/elasticsearch/reference/7.x/indices-create-index.html

2.2、index delete

curl -XDELETE 'http://10.143.228.25:9200/student?pretty'

response示例:

{"acknowledged" : true
}
  • 扩展阅读

https://www.elastic.co/guide/en/elasticsearch/reference/7.x/indices-delete-index.html

2.3、delete index aliases

curl -XDELETE 'http://10.143.228.25:9200/student/_alias/alias_1?pretty'

response示例:

{"acknowledged" : true
}
  • 扩展阅读

https://www.elastic.co/guide/en/elasticsearch/reference/7.x/indices-delete-alias.html

2.4、flush

支持如下几种形式

POST /<index>/_flush
GET /<index>/_flush
POST /_flush
GET /_flush

示例一(单个索引):

curl -XPOST 'http://10.143.228.25:9200/student/_flush?pretty'

response示例:

{"_shards" : {"total" : 2,"successful" : 2,"failed" : 0}
}

示例一(多个索引):

curl -XPOST 'http://10.143.228.25:9200/student,company/_flush?pretty'

response示例:

{"_shards" : {"total" : 4,"successful" : 4,"failed" : 0}
}
  • 扩展阅读

https://www.elastic.co/guide/en/elasticsearch/reference/7.x/indices-flush.html

2.5、get-field-mapping

支持如下几种形式

GET /_mapping/field/<field>
GET /<index>/_mapping/field/<field>

示例一:单个字段

curl -XGET 'http://10.143.228.25:9200/student/_mapping/field/name?pretty'

response示例:

{                                                                                                                                                       "student" : {                                                                                                                                         "mappings" : {                                                                                                                                      "name" : {"full_name" : "name","mapping" : {"name" : {"type" : "text"}}}}}
}

示例二:多个字段

curl -XGET 'http://10.143.228.25:9200/student/_mapping/field/name,age?pretty'

response示例:

{"student" : {"mappings" : {"name" : {"full_name" : "name","mapping" : {"name" : {"type" : "text"}}},"age" : {"full_name" : "age","mapping" : {"age" : {"type" : "integer"}}}}}
}
  • 扩展阅读

https://www.elastic.co/guide/en/elasticsearch/reference/7.x/indices-get-field-mapping.html

2.6、get-index

支持如下几种形式

GET /<index>
curl -XGET 'http://10.143.228.25:9200/student'

response示例:

{"student" : {"aliases" : {"alias_1" : { }},"mappings" : {"properties" : {"address" : {"type" : "text"},"age" : {"type" : "integer"},"birthday" : {"type" : "date"},"id" : {"type" : "long"},"name" : {"type" : "text"}}},"settings" : {"index" : {"creation_date" : "1590209646606","number_of_shards" : "3","number_of_replicas" : "2","uuid" : "l8Ih8QYSQTub3uNAmqWRrA","version" : {"created" : "7030299"},"provided_name" : "student"}}}
}
  • 扩展阅读

https://www.elastic.co/guide/en/elasticsearch/reference/7.x/indices-get-index.html

2.7、get-settings

支持如下几种形式

GET /<index>/_settings
GET /<index>/_settings/<setting>
# 单个
curl -XGET 'http://10.143.228.25:9200/student/_settings?pretty'
# 多个
curl -XGET 'http://10.143.228.25:9200/student,company/_settings?pretty'

response示例:

{"student" : {"settings" : {"index" : {"creation_date" : "1590209646606","number_of_shards" : "3","number_of_replicas" : "2","uuid" : "l8Ih8QYSQTub3uNAmqWRrA","version" : {"created" : "7030299"},"provided_name" : "student"}}}
}

response示例:

{"student" : {"settings" : {"index" : {"creation_date" : "1590209646606","number_of_shards" : "3","number_of_replicas" : "2","uuid" : "l8Ih8QYSQTub3uNAmqWRrA","version" : {"created" : "7030299"},"provided_name" : "student"}}},"company" : {"settings" : {"index" : {"creation_date" : "1589788313386","number_of_shards" : "1","number_of_replicas" : "1","uuid" : "ySjkNiAEQySBPH7eZ0HaYw","version" : {"created" : "7030299"},"provided_name" : "company"}}}
}
  • 扩展阅读

https://www.elastic.co/guide/en/elasticsearch/reference/7.x/indices-get-settings.html

2.8、put-mapping

Adds new fields to an existing index or changes the search settings of existing fields.

支持如下几种形式

PUT /<index>/_mapping
PUT /_mapping
  • 更新某个索引
curl -XPUT 'http://10.143.228.25:9200/student/_mapping?pretty' -H "Content-Type: application/json" -d '{"properties":{"address":{"type":"text"},"age":{"type":"integer"},"birthday":{"type":"date"},"id":{"type":"long"},"name":{"type":"text"}}}'
{"properties": {"address": {"type": "text"},"age": {"type": "integer"},"birthday": {"type": "date"},"id": {"type": "long"},"name": {"type": "text"}}
}

response示例:

{"acknowledged" : true
}
  • 扩展阅读

https://www.elastic.co/guide/en/elasticsearch/reference/7.x/indices-put-mapping.html

2.9、more APIs

https://www.elastic.co/guide/en/elasticsearch/reference/7.x/indices.html

下面的是我的公众号二维码图片,欢迎关注。
秋夜无霜

这篇关于ElasticSearch7.3.2-Rest实战指南-Index APIs的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/449529

相关文章

SpringBoot整合OpenFeign的完整指南

《SpringBoot整合OpenFeign的完整指南》OpenFeign是由Netflix开发的一个声明式Web服务客户端,它使得编写HTTP客户端变得更加简单,本文为大家介绍了SpringBoot... 目录什么是OpenFeign环境准备创建 Spring Boot 项目添加依赖启用 OpenFeig

SpringBoot请求参数接收控制指南分享

《SpringBoot请求参数接收控制指南分享》:本文主要介绍SpringBoot请求参数接收控制指南,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Spring Boot 请求参数接收控制指南1. 概述2. 有注解时参数接收方式对比3. 无注解时接收参数默认位置

CentOS7更改默认SSH端口与配置指南

《CentOS7更改默认SSH端口与配置指南》SSH是Linux服务器远程管理的核心工具,其默认监听端口为22,由于端口22众所周知,这也使得服务器容易受到自动化扫描和暴力破解攻击,本文将系统性地介绍... 目录引言为什么要更改 SSH 默认端口?步骤详解:如何更改 Centos 7 的 SSH 默认端口1

SpringBoot多数据源配置完整指南

《SpringBoot多数据源配置完整指南》在复杂的企业应用中,经常需要连接多个数据库,SpringBoot提供了灵活的多数据源配置方式,以下是详细的实现方案,需要的朋友可以参考下... 目录一、基础多数据源配置1. 添加依赖2. 配置多个数据源3. 配置数据源Bean二、JPA多数据源配置1. 配置主数据

python中各种常见文件的读写操作与类型转换详细指南

《python中各种常见文件的读写操作与类型转换详细指南》这篇文章主要为大家详细介绍了python中各种常见文件(txt,xls,csv,sql,二进制文件)的读写操作与类型转换,感兴趣的小伙伴可以跟... 目录1.文件txt读写标准用法1.1写入文件1.2读取文件2. 二进制文件读取3. 大文件读取3.1

SpringBoot中配置Redis连接池的完整指南

《SpringBoot中配置Redis连接池的完整指南》这篇文章主要为大家详细介绍了SpringBoot中配置Redis连接池的完整指南,文中的示例代码讲解详细,具有一定的借鉴价值,感兴趣的小伙伴可以... 目录一、添加依赖二、配置 Redis 连接池三、测试 Redis 操作四、完整示例代码(一)pom.

Linux内核参数配置与验证详细指南

《Linux内核参数配置与验证详细指南》在Linux系统运维和性能优化中,内核参数(sysctl)的配置至关重要,本文主要来聊聊如何配置与验证这些Linux内核参数,希望对大家有一定的帮助... 目录1. 引言2. 内核参数的作用3. 如何设置内核参数3.1 临时设置(重启失效)3.2 永久设置(重启仍生效

Python列表去重的4种核心方法与实战指南详解

《Python列表去重的4种核心方法与实战指南详解》在Python开发中,处理列表数据时经常需要去除重复元素,本文将详细介绍4种最实用的列表去重方法,有需要的小伙伴可以根据自己的需要进行选择... 目录方法1:集合(set)去重法(最快速)方法2:顺序遍历法(保持顺序)方法3:副本删除法(原地修改)方法4:

在Spring Boot中浅尝内存泄漏的实战记录

《在SpringBoot中浅尝内存泄漏的实战记录》本文给大家分享在SpringBoot中浅尝内存泄漏的实战记录,结合实例代码给大家介绍的非常详细,感兴趣的朋友一起看看吧... 目录使用静态集合持有对象引用,阻止GC回收关键点:可执行代码:验证:1,运行程序(启动时添加JVM参数限制堆大小):2,访问 htt

PyInstaller打包selenium-wire过程中常见问题和解决指南

《PyInstaller打包selenium-wire过程中常见问题和解决指南》常用的打包工具PyInstaller能将Python项目打包成单个可执行文件,但也会因为兼容性问题和路径管理而出现各种运... 目录前言1. 背景2. 可能遇到的问题概述3. PyInstaller 打包步骤及参数配置4. 依赖