elasticsearch如何新建索引+查询索引+删除索引+判断索引是否存在

elasticsearch如何新建索引+查询索引+删除索引+判断索引是否存在

1.es新建索引,并定义好索引类型

  • 输入
PUT /log
{
	"settings": {
		"number_of_shards": 3,
		"number_of_replicas": 2
	},
	"mappings": {
		"properties": {

			"id": {
				"type": "long"
			},
			"url": {
				"type": "text"
			},
			"accessTime": {
				"type": "text"
			},
			"userId": {
				"type": "long"
			},
			"param": {
				"type": "text"
			},
			"result": {
				"type": "text"
			}
		}
	}
}
  • 输出
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "log"
}

2.查看之前定义好的索引

  • 输入
GET /log/_mapping
  • 输出
{
  "log" : {
    "mappings" : {
      "properties" : {
        "accessTime" : {
          "type" : "text"
        },
        "id" : {
          "type" : "long"
        },
        "param" : {
          "type" : "text"
        },
        "result" : {
          "type" : "text"
        },
        "url" : {
          "type" : "text"
        },
        "userId" : {
          "type" : "long"
        }
      }
    }
  }
}

3.删除之前定好的索引

  • 输入
DELETE /log
  • 输出
{
  "acknowledged" : true
}

4.判断索引是否存在

  • 输入
HEAD /log
  • 输出

如果存在

200 - OK

如果不存在

{"statusCode":404,"error":"Not Found","message":"404 - Not Found"}

二.致谢

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html


版权声明:本文为qq_25955145原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。