注:Elasticsearch 6.0 之后建立索引时弃用type,即尽量不要在同一索引中建立多个类型,type全部使用_doc。以下命令全部在Kibana工具上操作:
一、索引操作:
1.创建索引:
PUT /twitter?pretty
2.获取索引:
GET /twitter
3.检查索引是否存在:
HEAD /twitter
4.删除索引:
DELETE /twitter
二、settings操作:
1.新建索引并且设置settings和mappings:
PUT /twitter
{
"settings" : {
"number_of_shards" : 5,
"number_of_replicas" : 1
},
"mappings" : {
"properties" : {
"field1" : { "type" : "text" }
}
}
}
2.获取setting:
GET /twitter/_settings
三、mappings(映射)操作:
映射是定义文档及其包含字段的存储和索引方式的过程。
1.单独设置mapping:
PUT /twitter/_mapping
{
"properties": {
"email": {
"type": "keyword"
}
}
}
2.获取mapping:
GET /twitter/_mapping
3.设置索引时设置mapping:
PUT /twitter
{
"mappings": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
}
},
"user_name": {
"type": "keyword"
},
"email": {
"type": "keyword"
},
"content": {
"type": "text"
},
"tweeted_at": {
"type": "date"
}
}
}
}
四、索引别名操作:
1.给索引增加别名:
POST /_aliases
{
"actions": [
{
"add": {
"index": "twitter",
"alias": "alias1"
}
}
]
}
2.删除索引别名:
POST /_aliases
{
"actions": [
{
"remove": {
"index": "twitter",
"alias": "alias1"
}
}
]
}
五、分析器:
1.标准分析器:
GET _analyze
{
"analyzer" : "standard",
"text" : "this is a test"
}
2.过滤器:
GET _analyze
{
"tokenizer" : "keyword",
"filter" : ["lowercase"],
"text" : "This Is A Test"
}
六、刷新:
1.刷新数据,让刚插入的数据可以被搜索到:
POST /twitter/_refresh
七、显示错误:
所有请求的URI后面带上(?error_trace=true)参数,可以显示错误的堆栈信息。例如:
GET /test_index/test_type/_search?error_trace=true