1) 显示当前ES的index列表
[root@node1 ~]# curl http://192.168.10.11:9200/_aliases?pretty
{ }
2) 创建一个index列表
[root@node1 ~]# curl -X PUT "http://192.168.10.11:9200/snow-index"
{"acknowledged":true,"shards_acknowledged":true,"index":"snow-index"}
3) 验证
[root@node1 ~]# curl http://192.168.10.11:9200/_aliases?pretty
{
"snow-index" : {
"aliases" : { }
}
}
[root@node1 ~]# curl http://192.168.10.11:9200/snow-index/_settings?pretty
{
"snow-index" : {
"settings" : {
"index" : {
"creation_date" : "1580740296271",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "kUMjzwJSQ2isMXX0o1pQOQ",
"version" : {
"created" : "7050299"
},
"provided_name" : "snow-index"
}
}
}
}
4) 定义映射并插入测试数据
[root@node1 1]# curl -H "Content-Type: application/json" -X PUT "http://192.168.10.11:9200/snow-index/doc01/1" -d '{
"subject" : "Test Post No.1",
"description" : "This is the initial post",
"content" : "This is the test message for using Elasticsearch."
}'
{"_index":"snow-index","_type":"doc01","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
5) 验证
[root@node1 ~]# curl "http://192.168.10.11:9200/snow-index/_mapping/?pretty"
{
"snow-index" : {
"settings" : {
"index" : {
"creation_date" : "1580740296271",
"number_of_shards" : "1",
"number_of_replicas" : "1",
"uuid" : "kUMjzwJSQ2isMXX0o1pQOQ",
"version" : {
"created" : "7050299"
},
"provided_name" : "snow-index"
}
}
}
}
[root@node1 ~]# curl -H "Content-Type: application/json" -X PUT "http://192.168.10.11:9200/snow-index/doc01/1" -d '{
"subject" : "Test Post No.1",
"description" : "This is the initial post",
"content" : "This is the test message for using Elasticsearch."
}'
{"_index":"snow-index","_type":"doc01","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_pri
mary_term":1}
[root@node1 ~]# curl "http://192.168.10.11:9200/snow-index/_mapping/?pretty"
{
"snow-index" : {
"mappings" : {
"properties" : {
"content" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"subject" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
6) 搜索数据(搜索条件为[Description]字段包含单词)
[root@node1 ~]# curl "http://192.168.10.11:9200/snow-index/doc01/_search?q=description:initial&pretty=true"
{
"took" : 146,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 0.2876821,
"hits" : [
{
"_index" : "snow-index",
"_type" : "doc01",
"_id" : "1",
"_score" : 0.2876821,
"_source" : {
"subject" : "Test Post No.1",
"description" : "This is the initial post",
"content" : "This is the test message for using Elasticsearch."
}
}
]
}
}
|