这些API负责管理索引的所有方面,如设置,别名,映射,索引模板。
此API可用于创建索引。 当用户将JSON对象传递到任何索引时,可以自动创建索引,也可以在此之前创建索引。 要创建索引,只需要发送包含设置,映射和别名的发布请求,或者只发送一个没有正文的简单请求。 例如
POST http://localhost:9200/colleges响应
{"acknowledged":true}
或者,加上一些设置
POST http://localhost:9200/colleges请求正文
{
"settings" : {
"index" : {
"number_of_shards" : 5, "number_of_replicas" : 3
}
}
}
响应
{"acknowledged":true}
或使用映射
POST http://localhost:9200/colleges请求正文
{
"settings" : {
"number_of_shards" : 3
},
"mappings" : {
"type1" : {
"_source" : { "enabled" : false }, "properties" : {
"college_name" : { "type" : "string" }, "college type" : {"type":"string"}
}
}
}
}
响应
{"acknowledged":true}
或者,用别名
POST http://localhost:9200/colleges请求正文
{
"aliases" : {
"alias_1" : {}, "alias_2" : {
"filter" : {
"term" : {"user" : "manu" }
},
"routing" : "manu"
}
}
}
响应
{"acknowledged":true}
删除索引
此API可用来删除任何索引。只需要传递一个删除请求以及指定索引的URL。 例如
DELETE http://localhost:9200/colleges
可以通过使用_all,*删除所有索引。
这个API可以通过发送get请求到一个或多个索引来调用。这将返回有关索引的信息。
GET http://localhost:9200/schools响应
{
"schools":{
"aliases":{}, "mappings":{
"school":{
"properties":{
"city":{"type":"string"}, "description":{"type":"string"},
"fees":{"type":"long"}, "location":{"type":"double"},
"name":{"type":"string"}, "rating":{"type":"string"},
"state":{"type":"string"}, "street":{"type":"string"},
"tags":{"type":"string"}, "zip":{"type":"string"}
}
}
},
"settings":{
"index":{
"creation_date":"1454409831535", "number_of_shards":"5",
"number_of_replicas":"1", "uuid":"iKdjTtXQSMCW4xZMhpsOVA",
"version":{"created":"2010199"}
}
},
"warmers":{}
}
}
可以使用_all或*来获取所有索引的信息。
可以通过向该索引发送获取请求来确定索引的存在。如果HTTP响应为200,则存在; 如果是404,它不存在。
通过在post中添加_close或_open来请求索引,可以很容易地关闭或打开一个或多个索引。 例如,
关闭索引
POST http://localhost:9200/schools/_close或打开索引
POST http://localhost:9200/schools/_open索引别名
此API有助于使用_aliases关键字向任何索引提供别名。 单个别名可以映射到多个别名,且别名不能与索引具有相同的名称。 例如
POST http://localhost:9200/_aliases请求正文
{
"actions" : [
{ "add" : { "index" : "schools", "alias" : "schools_pri" } }
]
}
响应
{"acknowledged":true}
然后
GET http://localhost:9200/schools_pri响应
{"schools":{"aliases":{"schools_pri":{}},"}}
索引设置
可以通过在URL结尾处附加_settings关键字来获取索引设置。 例如
GET http://localhost:9200/schools/_settings响应
{
"schools":{
"settings":{
"index":{
"creation_date":"1454409831535", "number_of_shards":"5",
"number_of_replicas":"1", "uuid":"iKdjTtXQSMCW4xZMhpsOVA",
"version":{"created":"2010199"}
}
}
}
}
分析
此API有助于分析文本并使用偏移值和数据类型发送令牌。 例如
POST http://localhost:9200/_analyze请求正文
{
"analyzer" : "standard",
"text" : "you are reading this at YIIBAI point"
}
响应
{
"tokens":[
{"token":"you", "start_offset":0, "end_offset":3, "type":"<ALPHANUM>", "position":0},
{"token":"are", "start_offset":4, "end_offset":7, "type":"<ALPHANUM>", "position":1},
{"token":"reading", "start_offset":8, "end_offset":15, "type":"<ALPHANUM>", "position":2},
{"token":"this", "start_offset":16, "end_offset":20, "type":"<ALPHANUM>", "position":3},
{"token":"at", "start_offset":21, "end_offset":23, "type":"<ALPHANUM>", "position":4},
{"token":"tutorials", "start_offset":24, "end_offset":33, "type":"<ALPHANUM>", "position":5},
{"token":"point", "start_offset":34, "end_offset":39, "type":"<ALPHANUM>", "position":6}
]
}
还可以使用任何索引分析文本,然后根据与该索引关联的分析器来分析文本。