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结合Docker进行容器化处理指南

《SpringBoot结合Docker进行容器化处理指南》在当今快速发展的软件工程领域,SpringBoot和Docker已经成为现代Java开发者的必备工具,本文将深入讲解如何将一个SpringBo... 目录前言一、为什么选择 Spring Bootjavascript + docker1. 快速部署与

MySQL 多列 IN 查询之语法、性能与实战技巧(最新整理)

《MySQL多列IN查询之语法、性能与实战技巧(最新整理)》本文详解MySQL多列IN查询,对比传统OR写法,强调其简洁高效,适合批量匹配复合键,通过联合索引、分批次优化提升性能,兼容多种数据库... 目录一、基础语法:多列 IN 的两种写法1. 直接值列表2. 子查询二、对比传统 OR 的写法三、性能分析

创建Java keystore文件的完整指南及详细步骤

《创建Javakeystore文件的完整指南及详细步骤》本文详解Java中keystore的创建与配置,涵盖私钥管理、自签名与CA证书生成、SSL/TLS应用,强调安全存储及验证机制,确保通信加密和... 目录1. 秘密键(私钥)的理解与管理私钥的定义与重要性私钥的管理策略私钥的生成与存储2. 证书的创建与

Python办公自动化实战之打造智能邮件发送工具

《Python办公自动化实战之打造智能邮件发送工具》在数字化办公场景中,邮件自动化是提升工作效率的关键技能,本文将演示如何使用Python的smtplib和email库构建一个支持图文混排,多附件,多... 目录前言一、基础配置:搭建邮件发送框架1.1 邮箱服务准备1.2 核心库导入1.3 基础发送函数二、

Python包管理工具pip的升级指南

《Python包管理工具pip的升级指南》本文全面探讨Python包管理工具pip的升级策略,从基础升级方法到高级技巧,涵盖不同操作系统环境下的最佳实践,我们将深入分析pip的工作原理,介绍多种升级方... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

PowerShell中15个提升运维效率关键命令实战指南

《PowerShell中15个提升运维效率关键命令实战指南》作为网络安全专业人员的必备技能,PowerShell在系统管理、日志分析、威胁检测和自动化响应方面展现出强大能力,下面我们就来看看15个提升... 目录一、PowerShell在网络安全中的战略价值二、网络安全关键场景命令实战1. 系统安全基线核查

Java操作Word文档的全面指南

《Java操作Word文档的全面指南》在Java开发中,操作Word文档是常见的业务需求,广泛应用于合同生成、报表输出、通知发布、法律文书生成、病历模板填写等场景,本文将全面介绍Java操作Word文... 目录简介段落页头与页脚页码表格图片批注文本框目录图表简介Word编程最重要的类是org.apach

Python设置Cookie永不超时的详细指南

《Python设置Cookie永不超时的详细指南》Cookie是一种存储在用户浏览器中的小型数据片段,用于记录用户的登录状态、偏好设置等信息,下面小编就来和大家详细讲讲Python如何设置Cookie... 目录一、Cookie的作用与重要性二、Cookie过期的原因三、实现Cookie永不超时的方法(一)

Linux中压缩、网络传输与系统监控工具的使用完整指南

《Linux中压缩、网络传输与系统监控工具的使用完整指南》在Linux系统管理中,压缩与传输工具是数据备份和远程协作的桥梁,而系统监控工具则是保障服务器稳定运行的眼睛,下面小编就来和大家详细介绍一下它... 目录引言一、压缩与解压:数据存储与传输的优化核心1. zip/unzip:通用压缩格式的便捷操作2.

从原理到实战深入理解Java 断言assert

《从原理到实战深入理解Java断言assert》本文深入解析Java断言机制,涵盖语法、工作原理、启用方式及与异常的区别,推荐用于开发阶段的条件检查与状态验证,并强调生产环境应使用参数验证工具类替代... 目录深入理解 Java 断言(assert):从原理到实战引言:为什么需要断言?一、断言基础1.1 语